xml_load

Loads an XML file and converts its content into a Jython variable.

 

Syntax

v = xml_load(filename,attswitch='on')

 

Description

xml_load reads the file given in parameter filename and uses xml_parse to convert it into a Jython data structure or variable. If the file cannot be found, an error will be displayed.

 

Input Arguments

filename   filename of xml file to load (if extension .xml is omitted, xml_load tries to append it if the file cannot be found).

 

attswitch optional, default='on':

'on' takes into account XML attributes idx, size, type

'off' ignores attributes in XML element headers.

 

Output Arguments

v                   Jython data structure or variable.

 

Examples

This example simply loads the sample file from the given location and converts its contents to a Jython data structure. (The file has previously been created using xml_save).

 

from gdxml import *

v = xml_load('c:/data/myfavourite.xml')

print v

 

{'name' : 'Google',

 'url' : 'http://www.google.com',

 'rating' : 5,

 'description' : 'Great search functionality for the web'}

 

In the following example, we perform the same action, however, as we are specifying the additional parameter 'off' for attributes, the idx, size, and type attributes are ignored and the result is slightly different: v['rating'] in this case is returned as a string variable, '5'.

 

v = xml_load('c:/data/myfavourite.xml','off')

print v

 

{'name' : 'Google',

 'url' : 'http://www.google.com',

 'rating' : '5',

 'description' : 'Great search functionality for the web'}

 

See also

xml_format , xml_parse , xml_save



xml_format

contents

xml_parse

Copyright © 2005, The Geodise Project, University of Southampton