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

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

added code to resolve hrefs and srsName refs to real objects

RevLine 
[630]1"""Test for GML/CSML parsing code
2"""
3from cElementTree import *
4from Parser import *
5from xml.dom.minidom import parseString
[780]6import sys
7import parser_extra
[632]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({
[780]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'})
[632]12
13
[742]14#######################################################
15# ElementTree-based parser test ROUND TRIP
16#######################################################
[630]17# 1. Test parsing from CSML file
[782]18#tree = ElementTree(file='example.xml')
19tree = ElementTree(file='era40gridseries.xml')
[630]20dataset = Dataset()
[742]21
22#Calling the fromXML method reads the CSML into memory.
[630]23dataset.fromXML(tree.getroot())
[742]24
25#Reading some values from memory and printing it out::
[775]26#print dataset.featureCollection.members[3].profileSeriesDomain.domainReference.times.href
[742]27
[780]28#resolve references: (not implemented yet)
[782]29dataset=parser_extra.ParserPostProcessor(dataset).resolveReferences()
[775]30
[742]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.
[630]33csml = dataset.toXML()
[655]34
[742]35#Tidy up and print the CSML document:
[655]36strCSML= parseString(tostring(csml)).toprettyxml()
[780]37strCSML=parser_extra.removeInlineNS(strCSML)
[782]38print strCSML
[632]39
Note: See TracBrowser for help on using the repository browser.