source: TI02-CSML/trunk/csml/csml2Moles/addnewElemTest.py @ 1904

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/csml2Moles/addnewElemTest.py@2047
Revision 1904, 1012 bytes checked in by domlowe, 13 years ago (diff)

Namespaces are now handled properly (I think!). Also added new file addnewElemTest.py to show how to add new elements to a pre-existing MOLES document

Line 
1#!/usr/bin/env python
2import csml.parser
3import cElementTree
4import elementtree.ElementTree as etree
5import molesReadWrite as MRW
6
7
8def main():
9    M=MRW.MolesDoc()
10    #read in XML to python
11    tree=cElementTree.ElementTree(file='test.xml')
12    dgMeta=MRW.dgMetadata()
13    dgMeta.fromXML(tree.getroot())
14   
15    #Example of adding a new dgStructuredKeyword to an existing moles xml doc using addChildElem
16    strValidTerm='TEST 2nd kword climatologyMeteorologyAtmosphere'
17    strParentID='2 ISO 19115 - Geographic Information Metadata Topic Category Code List'
18    strTermID='2004'
19    dgVTID=M.dgValidTermID(ParentListID=strParentID, TermID=strTermID)
20    dgSK=M.dgStructuredKeyword(dgValidTerm=strValidTerm, dgValidTermID=dgVTID)
21    dgMeta.dgMetadataRecord.addChildElem('dgStructuredKeyword', dgSK)
22
23    #regenerate XML from python
24    molestree=dgMeta.toXML()
25    moles=csml.parser_extra.PrettyPrint(molestree)
26    print '\n \n \n AFTER PARSING'
27    print moles   
28   
29if __name__=='__main__':
30    main()
Note: See TracBrowser for help on using the repository browser.