Parse Method

This method parses the specified XML data.

Syntax

xml.parse([callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method parses the specified XML data.

When parsing a document events will fire to provide information about the parsed data. After Parse returns the document may be navigated by setting XPath if BuildDOM is True (default). If BuildDOM is False parsed data is only accessible through the events.

Events are fired only when qualifying conditions (such as, for example, the beginning of a new element) are met. In the meantime, text will be buffered internally. The following events will fire during parsing:

If BuildDOM is True (default), XPath may be set after this method returns. XPath implements a subset of the XML XPath specification, allowing you to point to specific elements in the XML documents.

The path is a series of one or more element accessors separated by '/'. The path can be absolute (starting with '/') or relative to the current XPath location.

The following are possible values for an element accessor:

'name'A particular element name
name[i]The i-th subelement of the current element with the given name
[i]The i-th subelement of the current element
[last()]The last subelement of the current element
[last()-i]The subelement located at the last location minus i in the current element
name[@attrname="attrvalue"]The subelement containing a particular value for a given attribute (supports single AND double quotes)
..The parent of the current element

When XPath is set to a valid path, XElement points to the name of the element, with XParent, XNamespace, XPrefix, XChildName, XChildNamespace, XChildPrefix, XChildXText, and XText providing other properties of the element. The attributes of the current element are provided in the AttrName, AttrNamespace, AttrPrefix, and AttrValue properties.

BuildDOM must be set to True prior to parsing the document for the XPath functionality to be available.

Example (Setting XPath):

Document rootXML.XPath = "/"
Specific ElementXML.XPath = "/root/SubElement1/SubElement2/"
i-th ChildXML.XPath = "/root/SubElement1[i]"

Input Properties

The class will determine the source of the input based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops.

If parsing multiple documents call Reset between documents to reset the parser.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks 2020 Node.js Edition - Version 20.0 [Build 8307]