Ignore:
Timestamp:
04/02/08 10:10:21 (12 years ago)
Author:
domlowe
Message:

updating basictest.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/Examples/Parsing/basictest.py

    r2204 r3294  
    1 """Test for GML/CSML parsing code 
     1"""Test for CSML parsing code 
    22""" 
    3 from cElementTree import * 
    4 import sys 
     3 
    54import 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'}) 
     5 
     6#Name of test file 
     7f='example.xml' 
     8 
     9#Create empty dataset object and parse the file into it. 
     10#This creates a new CSML document string from the CSML objects in memory. 
     11dataset=csml.parser.Dataset() 
     12dataset.parse(f) 
    1013 
    1114 
    12 ####################################################### 
    13 # ElementTree-based parser test ROUND TRIP 
    14 ####################################################### 
    15 # 1. Test parsing from CSML file 
    16 tree = ElementTree(file='/gridseries/testout.xml') 
    17 #tree = ElementTree(file='nagridseries.xml') 
    18 #tree = ElementTree(file='bodc.xml') 
    19 dataset = csml.parser.Dataset() 
     15#Output the CSML from the dataset object as a string.  
     16#Hopefully the CSML output should be the same as the CSML it read in: 
     17csmldoc = dataset.toXML() 
    2018 
    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 csmldoc = dataset.toXML() 
    33 #print str(csmldoc) 
    34      
    3519#Tidy up and print the CSML document: 
    36 #strCSML= parseString(tostring(csml)).toprettyxml() 
    3720strCSML=csml.parser_extra.PrettyPrint(csmldoc) 
    3821strCSML=csml.parser_extra.removeInlineNS(strCSML) 
    3922print strCSML 
    4023 
    41  
Note: See TracChangeset for help on using the changeset viewer.