The XMLParser class enables reading data from XML files. More...
The T/HIS JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
Detailed DescriptionThe XMLParser class provides a stream-oriented parser to enable you to read XML files.
You register callback (or handler) functions with the parser and then parse the document.
As the parser recognizes parts of the document, it will call the appropriate handler for that part
(if you've registered one.) The document is fed to the parser in pieces. This allows you to parse
really huge documents that won't fit into memory. |
// Create a new parser object
var p = new XMLParser();
// assign handlers
p.startElementHandler = startElem;
p.endElementHandler = endElem;
p.characterDataHandler = text;
p.commentHandler = comment;
// parse the file
p.Parse("/data/test.xml");
////////////////////////////////////////////////////////////////////////////////
function startElem(name, attr)
{
// handler to be called when a start element is found
// Print element name
Println("START: " + name);
// Print attributes
for (n in attr)
{
Println(" attr: " + n + "=" + attr[n]);
}
}
function endElem(name)
{
// handler to be called when an end element is found
// Print element name
Println("END: " + name);
}
function text(str)
{
// handler to be called when text is found
// Print text
Println("TEXT: '" + str + "'");
}
function comment(str)
{
// handler to be called when a comment is found
// Print comment
Println("COMMENT: '" + str + "'");
}
See the documentation below for more details.
Constructornew XMLParser()DescriptionCreate a new XMLParser object for reading XML files. |
No arguments
ReturnsXMLParser object Return typeXMLParser |
ExampleTo create a new XMLParser object var p = new XMLParser();
|
Details of functionsParse(filename[string])Descriptionstarts parsing an XML file |
XML file to parse
ReturnsNo return value |
ExampleTo parse XML file "/data/test.xml"
var p = new XMLParser();
p.Parse("/data/test.xml");
|