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

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

basictest.py added - simple round trip parser test

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