Caplin Trader 4.8.0

Class: module:br/util/XmlParser

module:br/util/XmlParser

Utility class that provides methods for parsing XML strings into Document Objects. The object is a singleton so require('br/util/XmlParser') should be used to obtain an instance of an XmlParser.

Example:

var oXmlParser = br.util.XmlParser;
var oDocument = oXmlParser.parse("<test />");
alert(oDocument.tagName);

The module:br/util/XmlUtility singleton provides further helper methods to manipulate XML.

Constructor

new module:br/util/XmlParser()

Constructs a XmlParser. This has been included for backwards compatibility.

It is recommended that the module:br/util/XmlParser#getInstance method is used to get an instance instead of generating a new XmlParser every time.

Methods

(static) parse(xml) → {DOMDocument}

Parses an XML string, stripping out any whitespace and comments, and returns a document object representation.

This method supersedes #parseString as it will return an XML DOM that is consistent across different browsers. All comments and unnecessary whitespace characters will be stripped out of the XML DOM.

Any encoded characters within the specified string (such as &) will be decoded in the returned DOMDocument. Please see module:br/util/XmlUtility for more information on character encoding in XML.

Parameters:
Name Type Description
xml String The XML string to be parsed.
Returns:
An XML DOM representing the specified XML. If the XML failed to be parsed an XML DOM with the root node parsererror will be returned.
Type
DOMDocument

(static) stripWhitespace(xml) → {String}

Strips out all of the unnecessary whitespace characters from the specified XML string. These are the whitespace characters stripped at the beginning and end of the string, and in between each of the tags. This makes parsing of the XML easier in Firefox which includes the whitespace within the DOM tree.
Parameters:
Name Type Description
xml String The XML to have the whitespace stripped from.
See:
Returns:
The XML with all unnecessary whitespace characters stripped out.
Type
String