Ignore:
Timestamp:
04/02/08 10:26:11 (13 years ago)
Author:
domlowe
Message:

Added optional file keyword to Dataset init method. Added toPrettyXML() method.

File:
1 edited

Legend:

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

    r3294 r3295  
    77f='example.xml' 
    88 
    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. 
    11 dataset=csml.parser.Dataset() 
    12 dataset.parse(f) 
     9#Create empty dataset object and parse the file,f into it. 
     10#This creates a new CSML document string from the CSML objects in memory: 
     11dataset=csml.parser.Dataset(file=f) 
    1312 
     13#or the long way: 
     14#dataset=csml.parser.Dataset() 
     15#dataset.parse(f) 
    1416 
    15 #Output the CSML from the dataset object as a string.  
     17#Now output the CSML from the dataset object. 
    1618#Hopefully the CSML output should be the same as the CSML it read in: 
     19 
     20#the toXML() method returns an elementtree element instance: 
    1721csmldoc = dataset.toXML() 
     22print csmldoc 
    1823 
     24#And the toPrettyXML() method returns a string, with correct formatting and namespaces. 
    1925#Tidy up and print the CSML document: 
    20 strCSML=csml.parser_extra.PrettyPrint(csmldoc) 
    21 strCSML=csml.parser_extra.removeInlineNS(strCSML) 
     26strCSML=dataset.toPrettyXML() 
    2227print strCSML 
    2328 
Note: See TracChangeset for help on using the changeset viewer.