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

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

support for resolving FileList? Xlinks.

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/testout2.xml')
18
19#tree = ElementTree(file='nagridseries.xml')
20#tree = ElementTree(file='bodc.xml')
21dataset = csml.parser.Dataset()
22
23#Calling the fromXML method reads the CSML into memory.
24
25dataset.fromXML(tree.getroot())
26#Reading some values from memory and printing it out::
27#print dataset.featureCollection.members[3].profileSeriesDomain.domainReference.times.href
28
29#resolve references:
30dataset=csml.parser_extra.ParserPostProcessor(dataset).resolveReferences()
31
32#This creates a new CSML document string from the CSML objects in memory.
33#Hopefully the CSML output should be the same as the CSML it read in.
34csmldoc = dataset.toXML()
35 
36#Tidy up and print the CSML document:
37#strCSML= parseString(tostring(csml)).toprettyxml()
38strCSML=csml.parser_extra.PrettyPrint(csmldoc)
39strCSML=csml.parser_extra.removeInlineNS(strCSML)
40print strCSML
41
Note: See TracBrowser for help on using the repository browser.