1 | """Test for GML/CSML parsing code |
---|
2 | """ |
---|
3 | from cElementTree import * |
---|
4 | import sys |
---|
5 | import csml |
---|
6 | import elementtree.ElementTree as etree |
---|
7 | #this is a fix to the ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. |
---|
8 | etree._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='example.xml') |
---|
17 | #tree = ElementTree(file='nagridseries.xml') |
---|
18 | #tree = ElementTree(file='bodc.xml') |
---|
19 | dataset = csml.parser.Dataset() |
---|
20 | |
---|
21 | #Calling the fromXML method reads the CSML into memory. |
---|
22 | |
---|
23 | dataset.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. |
---|
32 | csmlf = dataset.toXML() |
---|
33 | #print str(csml) |
---|
34 | |
---|
35 | #Tidy up and print the CSML document: |
---|
36 | #strCSML= parseString(tostring(csml)).toprettyxml() |
---|
37 | strCSML=csml.parser_extra.PrettyPrint(csmlf) |
---|
38 | strCSML=csml.parser_extra.removeInlineNS(strCSML) |
---|
39 | print strCSML |
---|
40 | |
---|
41 | |
---|