Changeset 1735 for TI02-CSML


Ignore:
Timestamp:
22/11/06 10:21:25 (13 years ago)
Author:
domlowe
Message:

removed self.NAMESPACE and moved ownership of namespace to individual elements rather than to classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/branches/CSML2/csParser.py

    r1734 r1735  
    11import cElementTree as ET 
     2import elementtree.ElementTree as etree 
    23import csml.parser_extra 
    34 
    45'''CSML v2 Parser '''  
     6 
     7#note to self. Not sure we need self.NAMESPACE as namespace info is held in the element name. 
     8 
     9etree._namespace_map.update({ 
     10    'http://www.opengis.net/om': 'om',  'http://www.opengis.net/gml': 'gml','http://ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'}) 
    511 
    612 
     
    3945            self.ATTRIBUTES=[] 
    4046             
     47         
     48    def __removeURI(self, qname): 
     49        try: 
     50            attname = qname.split('}')[1] 
     51        except IndexError: 
     52            attname = qname 
     53        return attname 
     54 
    4155    def toXML(self, csmlfrag): 
    4256    #process self... and convert  to XML  
     
    4458            if item in self.ATTRIBUTES: 
    4559                csmlfrag.set(item, self.__dict__[item]) 
     60         #but probably need to handle the case where GML attributes are set without namespace 
     61         #to allow for  use of classname(id = 'blah')  
     62        for item in self.__dict__: 
     63            if GML(item) in self.ATTRIBUTES: 
     64                csmlfrag.set(GML(item), self.__dict__[item])        
     65          
    4666    # self.CHILDREN (recursive - calls the toXML method of children) 
    4767        for att in self.__dict__: 
    48             if att not in ['NAMESPACE', 'ATTRIBUTES', 'CHILDREN', 'CONTENT']: 
     68            if att not in ['ATTRIBUTES', 'CHILDREN', 'CONTENT']: 
    4969                for child in self.CHILDREN: 
    5070                    if child == att: 
     
    7898            for child in self.CHILDREN: 
    7999                ename = self.CHILDREN[child][0] #Element Name  
    80                 if frag.tag == myQName(self.NAMESPACE, ename): 
     100                if frag.tag == ename: 
    81101                    etype = self.CHILDREN[child][1] 
    82102                    #Element Type                    #elem = ET.Element(ename) 
     
    97117    
    98118    def __init__(self, **kwargs): 
    99         self.ATTRIBUTES=[GML('id'), 'description'] # etc 
     119        self.ATTRIBUTES=[GML('id'), GML('description')] # etc 
    100120    #ATTRIBUTES not implemented yet. 
    101121     
     
    104124    def __init__(self,**kwargs): 
    105125        AbstractGML.__init__(self,**kwargs) 
    106         self.NAMESPACE= nsCSML 
    107         self.CHILDREN = {'fileName':['fileName', 'csString']} 
     126        self.CHILDREN = {'fileName':[CSML('fileName'), 'csString']} 
    108127 
    109128class NetCDFExtract(AbstractFileExtract, csElement): 
    110129    def __init__(self,**kwargs): 
    111130        AbstractFileExtract.__init__(self, **kwargs) 
    112         self.NAMESPACE= nsCSML 
    113         self.CHILDREN = Merge(self.CHILDREN,{'variableName':['variableName', 'csString']}) 
     131        self.CHILDREN = Merge(self.CHILDREN,{'variableName':[CSML('variableName'), 'csString']}) 
    114132        #use Merge() when inheriting CHILDREN attribute to extend rather than replace 
    115133 
     
    119137    def __init__(self, **kwargs): 
    120138        AbstractGML.__init__(self,**kwargs) 
    121         self.NAMESPACE=nsCSML 
    122         self.CHILDREN = {'ncExtract':['NetCDFExtract', 'NetCDFExtract']} 
     139        self.CHILDREN = {'ncExtract':[CSML('NetCDFExtract'), 'NetCDFExtract']} 
    123140    def toXML(self): 
    124         csmlfrag=ET.Element('Dataset') 
     141        csmlfrag=ET.Element(CSML('Dataset')) 
    125142        csElement.toXML(self, csmlfrag) 
    126143        return csmlfrag 
     
    137154    #print dir(csmlout) 
    138155 
     156    #test writing a document from scratch: 
     157     
    139158 
    140159if __name__=='__main__': 
Note: See TracChangeset for help on using the changeset viewer.