Changeset 2430


Ignore:
Timestamp:
24/04/07 12:06:53 (12 years ago)
Author:
domlowe
Message:

csml access to exist, working except for namespace issue

Location:
TI02-CSML/trunk/csml/API
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/API/ops_Dataset.py

    r2215 r2430  
    44import csml.csmllibs.xmlEncoding 
    55import csml.parser_extra 
     6import csml.API.existDB 
     7import cElementTree as ET 
     8import elementtree.ElementTree 
     9 
    610 
    711def testmethod(self): 
     
    913    return 'testmethod dataset' 
    1014 
    11 def parse(self,csmlfile): 
     15def parse(self, csmlfile, xmldb=None, collection='/db/ndg_A_metadata', id_field = 'id', nslong='http://ndg.nerc.ac.uk/csml', nsshort='csml', passwords=None): 
    1216    """must be provided with csmlfile   parses the csmlfile into self """ 
    13     #determine encoding 
    14     f = open(csmlfile) 
    15     startoffile=f.readline() 
    16     encoding=csml.csmllibs.xmlEncoding.autoDetectXMLEncoding(startoffile) 
    17     f.close() 
    18     #parse with correct encoding 
    19     tree = csml.parser_extra.encodingParser(csmlfile,encoding) 
     17    if xmldb is not None:       
     18        #use xml db (exist) 
     19        COLLECTION=collection 
     20        DOC_ID=csmlfile 
     21        ID_FIELD=id_field 
     22        NSLONG=nslong 
     23        NSSHORT=nsshort 
     24        if passwords is not None: 
     25            existDB = csml.API.existDB.ndg_eXist(db=xmldb, passwordFile=passwords)   
     26        else: 
     27            existDB = csml.API.existDB.ndg_eXist(db=xmldb)   
     28        csmlfile=existDB.getXMLRecord(COLLECTION,ID_FIELD,DOC_ID,att=1,namespaceLong=NSLONG, namespaceShort=NSSHORT) 
     29        elem=elementtree.ElementTree.fromstring(csmlfile) 
     30        tree=ET.ElementTree(element=elem) 
     31    else: 
     32        #use filesystem 
     33        #determine encoding 
     34        f = open(csmlfile) 
     35        startoffile=f.readline() 
     36        encoding=csml.csmllibs.xmlEncoding.autoDetectXMLEncoding(startoffile) 
     37        f.close() 
     38        #parse with correct encoding 
     39        tree = csml.parser_extra.encodingParser(csmlfile,encoding) 
    2040    self.fromXML(tree.getroot()) 
    2141    self =csml.parser_extra.ParserPostProcessor(self).resolveReferences() 
Note: See TracChangeset for help on using the changeset viewer.