XML Parser

XML Parser JavaScript API

The XML Parser allows you to transform an XML-string into a queryable object, XPathNavigator.

var xmlObj = XML.parse('<xml><element attribute="value1" /><element attribute="value2" /></xml>');



This object exposes properties and methods to query an XML element easily using X-Path.


value: string

The XML object’s value. If the object is an element, the value is the text inside between start and end tags or the inner XML content if applicable. If the object is an attribute, the value is the attribute’s value.

var firstElement = xmlObj.selectFirst('/xml/element/@attribute');
var value = firstElement.value;
// The value should be equal to "value1".


selectFirst(x-path: string): XPathNavigator

Returns the first occurrence of the provided X-Path, or undefined if there are no occurrences.

var element = xmlObj.selectFirst('/xml/element');
// Should return the first <element> inside the <xml> node.

select(x-path: string): XPathNavigator

Returns an array with all occurrences of the provided X-Path, or an empty array if no occurrences.

var elements = xmlObj.select('/xml/element');
// Should return an array with all <element> inside the <xml> node.

toString(): string

Returns a string representation of the XML element.

var element = xmlObj.selectFirst('/xml/element');
var value = element.toString()
// The value should be equal to "<element attribute="value1" />".