Ignore:
Timestamp:
19/12/06 09:19:29 (14 years ago)
Author:
domlowe
Message:

added addChildElem method to csElement class

File:
1 edited

Legend:

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

    r1883 r1890  
    8282    def _getReverseSubsType(self, typename): 
    8383        return typename 
    84     
     84     
     85    def addChildElem(self, childname, childobj): 
     86        #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. 
     87        if hasattr(self, childname): 
     88            currentattribute=getattr(self,childname) 
     89            if type(getattr(self,childname)) is list: 
     90                currentattribute.append(childobj) 
     91            else: 
     92                newlist=[currentattribute] 
     93                newlist.append(childobj) 
     94                setattr(self,childname, newlist) 
     95        else: 
     96            setattr(self,childname, childobj) 
     97 
    8598    def toXML(self, csmlfrag): 
    8699        #process self and convert to XML 
Note: See TracChangeset for help on using the changeset viewer.