source: TI02-CSML/trunk/newparser/test.py @ 883

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

basic temporal subsetting implemented, basic spatial part done

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