- Timestamp:
- 30/10/06 14:43:59 (13 years ago)
- Location:
- TI02-CSML/trunk/csml2MolesStuff
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml2MolesStuff/csml2moles.py
r1643 r1650 209 209 210 210 print '\n \n \n BEFORE PARSING' 211 print moles211 #print moles 212 212 f=open('molesout.xml','w') 213 213 f.write(moles) … … 220 220 dgMeta.fromXML(tree.getroot()) 221 221 molestree=dgMeta.toXML() 222 #print cElementTree.dump(molestree) 222 223 moles=csml.parser_extra.PrettyPrint(molestree) 223 224 print '\n \n \n AFTER PARSING' 224 print moles 225 #print moles 226 f=open('molesout2.xml','w') 227 f.write(moles) 228 f.close() 225 229 226 230 if __name__=='__main__': -
TI02-CSML/trunk/csml2MolesStuff/molesWriter.py
r1643 r1650 1 # prototype MOLES generation code.Dominic Lowe, BADC 18 October 20061 #Dominic Lowe, BADC 18 October 2006 2 2 3 3 import cElementTree as ET 4 import csml.parser_extra #note this is only used for pretty printing - there's no dependency on the CSML parser 4 5 5 class molesElement(object): 6 6 def __init__(self, **kwargs): … … 13 13 if isinstance(att,molesElement): 14 14 setattr(self,attname,[att, newChild]) 15 else: #must be a list?15 else: 16 16 att.append(newChild) 17 17 setattr(self, attname,att) … … 38 38 molesFrag.append(frag) 39 39 return molesFrag 40 40 41 41 def fromXML(self,molesFrag): 42 print molesFrag.tag43 42 children = molesFrag.getchildren() 44 print ' has %s'%children45 43 if children ==[]: 46 #this shouldn't occur as a molesElement always has children 47 #print 'no children' 48 pass 44 setattr(self,molesElement.tag, molesElement.text) 49 45 if children!=[]: 50 #print 'has children'51 46 for child in children: 52 47 print child … … 62 57 else: 63 58 setattr(self,child.tag, child.text) 59 64 60 65 61 class dgMetadata(molesElement): … … 102 98 'metadataDescriptionID',\ 103 99 'dgMetadataDescription', \ 104 'fruit']100 ] 105 101 106 102 for className in classList: … … 108 104 setattr(self,className,newClass) 109 105 110 # def main():111 # #example how to create classes:112 # M=MolesDoc()113 # M._createClasses()114 #115 # '''create your moles doc by setting attributes of "M.className"116 # the classNames used must be declared in molesWriter.MolesDoc.classList'''117 # dgMID=M.dgMetadataID(schemeIdentifier='NDG-B0', repositoryIdentifier='badc.nerc.ac.uk', localIdentifier='COAPEC_HadCM3_500Yr')118 # dmID= M.dataModelID(schemeIdentifier='NDG-A0', repositoryIdentifier='badc.nerc.ac.uk', localIdentifier='COAPEC_500YrRun_wholerun_annual_atmos')119 # dmID2= M.dataModelID(schemeIdentifier='NDG-A0', repositoryIdentifier='badc.nerc.ac.uk', localIdentifier='COAPEC_500YrRun_wholerun_annual_oceanls')120 # DG1 = M.dgDataGranule(dataModelID=dmID)121 # DG2 = M.dgDataGranule(dataModelID=dmID2)122 # dgDE= M.dgDataEntity(dgDataGranule=[DG1,DG2])123 # dgMR=M.dgMetadataRecord(dgMetadataID=dgMID, dgDataEntity=dgDE)124 # dgMeta=dgMetadata(dgMetadataRecord=dgMR)125 #126 # #print it out.127 # molestree=dgMeta.toXML()128 # moles=csml.parser_extra.PrettyPrint(molestree)129 # print moles130 #131 # if __name__=='__main__':132 # main()
Note: See TracChangeset
for help on using the changeset viewer.