source: TI02-CSML/trunk/parser/test.py @ 1147

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/parser/test.py@1178
Revision 1147, 1.5 KB checked in by domlowe, 14 years ago (diff)

Added CSML security metadata: example.xml contains sample csml security tags (same as MOLES). Parser now parses security elements. CSML Schema has been revised and will be committed separately.

Line 
1"""Test for GML/CSML parsing code
2"""
3from cElementTree import *
4from Parser import *
5from xml.dom.minidom import parseString
6import sys
7import parser_extra
8import elementtree.ElementTree as etree
9#this is a fix to the  ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc.
10etree._namespace_map.update({
11        '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'})
12
13
14#######################################################
15# ElementTree-based parser test ROUND TRIP
16#######################################################
17# 1. Test parsing from CSML file
18tree = ElementTree(file='example.xml')
19#tree = ElementTree(file='nagridseries.xml')
20#tree = ElementTree(file='bodc.xml')
21dataset = 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:
30#dataset=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.
34csml = dataset.toXML()
35#print str(csml)
36   
37#Tidy up and print the CSML document:
38#strCSML= parseString(tostring(csml)).toprettyxml()
39strCSML=parser_extra.PrettyPrint(csml)
40strCSML=parser_extra.removeInlineNS(strCSML)
41print strCSML
42
43
Note: See TracBrowser for help on using the repository browser.