source: TI02-CSML/trunk/csml/testfiles/basictest.py @ 2060

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/testfiles/basictest.py@2060
Revision 2060, 1.5 KB checked in by domlowe, 13 years ago (diff)

default calendar attribute added, repitition in fileList removed, gml:description fixed

Line 
1
2
3from cElementTree import *
4import sys
5import csml
6import elementtree.ElementTree as etree
7#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc.
8etree._namespace_map.update({
9        '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'})
10
11
12#######################################################
13# ElementTree-based parser test ROUND TRIP
14#######################################################
15# 1. Test parsing from CSML file
16#tree = ElementTree(file='../XMLInstances/CSMLExample_SuperWrap.xml')
17tree = ElementTree(file='../testfiles/gridseries/testout.xml')
18
19   
20#tree = ElementTree(file='nagridseries.xml')
21#tree = ElementTree(file='bodc.xml')
22dataset = csml.parser.Dataset()
23
24#Calling the fromXML method reads the CSML into memory.
25
26dataset.fromXML(tree.getroot())
27
28#Reading some values from memory and printing it out::
29#print dataset.featureCollection.members[3].profileSeriesDomain.domainReference.times.href
30
31#resolve references:
32dataset=csml.parser_extra.ParserPostProcessor(dataset).resolveReferences()
33
34#This creates a new CSML document string from the CSML objects in memory.
35#Hopefully the CSML output should be the same as the CSML it read in.
36csmldoc = dataset.toXML()
37 
38   
39#try another iteration:
40#Tidy up and print the CSML document:
41#strCSML= parseString(tostring(csml)).toprettyxml()
42strCSML=csml.parser_extra.PrettyPrint(csmldoc)
43strCSML=csml.parser_extra.removeInlineNS(strCSML)
44print strCSML
45
Note: See TracBrowser for help on using the repository browser.