Skip to content

Function: parseXml() ​

ts
function parseXml(input, options?): XmlNode;

Defined in: xml/src/parseXml.ts:106

Parse XML into a JS object

The parser does not validate against a DTD or schema, and it does not check every well-formedness constraint; the errors it does report are listed below under Throws. Input cut off between tags yields the nodes parsed so far.

Parameters ​

input ​

string

The input XML string

options? ​

XmlParseOptions = {}

Optional parsing options

Returns ​

XmlNode

The parsed XML

Throws ​

If an attribute is not name="value" or name='value', if a quoted value is not closed, if a close tag does not match its open tag, or if a close tag appears with no element open

Example ​

ts
const obj = parseXml(
	`<root>
		<child>text</child>
		<ns:tag>content</ns:tag>
	</root>`,
)
assert(obj.childNodes[0].nodeName === 'root')
assert(obj.childNodes[0].childNodes[0].nodeName === 'child')
assert(obj.childNodes[0].childNodes[0].childNodes[0].nodeValue === 'text')
assert(obj.childNodes[0].childNodes[1].nodeName === 'ns:tag')
assert(obj.childNodes[0].childNodes[1].prefix === 'ns')
assert(obj.childNodes[0].childNodes[1].localName === 'tag')

A Streaming Video Technology Alliance project.