Changeset 1891


Ignore:
Timestamp:
19/12/06 09:24:36 (13 years ago)
Author:
domlowe
Message:

added addChildElem method to molesElement class in moles parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml2MolesStuff/molesReadWrite.py

    r1855 r1891  
    9191            att.append(newChild) 
    9292            setattr(self, attname,att) 
    93          
     93     
     94    modef addChildElem(self, childname, childobj): 
     95        #sometimes you want to add a child element but don't know if there is one already. In which case you want to create a list of child objects. 
     96        if hasattr(self, childname): 
     97            currentattribute=getattr(self,childname) 
     98            if type(getattr(self,childname)) is list: 
     99                currentattribute.append(childobj) 
     100            else: 
     101                newlist=[currentattribute] 
     102                newlist.append(childobj) 
     103                setattr(self,childname, newlist) 
     104        else: 
     105            setattr(self,childname, childobj) 
     106     
    94107    def toXML(self,molesFrag, schema=None): 
    95108        if schema != None: 
     
    180193        'metadataDescriptionID',\ 
    181194        'dgMetadataDescription', \ 
    182         'dgStructuredKeyword', \ 
    183         ] 
     195        'dgStructuredKeyword', \ 
     196        ] 
     197 
    184198 
    185199        for className in classList: 
Note: See TracChangeset for help on using the changeset viewer.