Class: shaka.util.XmlUtils

A set of XML utility functions.

Constructor

new XmlUtils()

A set of XML utility functions.

Source:

Methods

evalDivision(exprString) → {number}

Evaluate a division expressed as a string.
Parameters:
Name Type Description
exprString string The expression to evaluate, e.g. "200/2". Can also be a single number.
Source:
Returns:
The evaluated expression as floating point number on success; otherwise return null.
Type
number

findChild(elemnon-null, name) → {Element}

Finds a child XML element.
Parameters:
Name Type Description
elem Node The parent XML element.
name string The child XML element's tag name.
Source:
Returns:
The child XML element, or null if a child XML element does not exist with the given tag name OR if there exists more than one child XML element with the given tag name.
Type
Element

findChildNS(elemnon-null, ns, name) → {Element}

Finds a namespace-qualified child XML element.
Parameters:
Name Type Description
elem Node The parent XML element.
ns string The child XML element's namespace URI.
name string The child XML element's local name.
Source:
Returns:
The child XML element, or null if a child XML element does not exist with the given tag name OR if there exists more than one child XML element with the given tag name.
Type
Element

findChildren(elemnon-null, name) → {Array.<!Element>}

Finds child XML elements.
Parameters:
Name Type Description
elem Node The parent XML element.
name string The child XML element's tag name.
Source:
Returns:
The child XML elements.
Type
Array.<!Element>

findChildrenNS(elemnon-null, ns, name) → {Array.<!Element>}

Finds namespace-qualified child XML elements.
Parameters:
Name Type Description
elem Node The parent XML element.
ns string The child XML element's namespace URI.
name string The child XML element's local name.
Source:
Returns:
The child XML elements.
Type
Array.<!Element>

getAttributeNS(elemnon-null, ns, name) → {string}

Gets a namespace-qualified attribute.
Parameters:
Name Type Description
elem Element The element to get from.
ns string The namespace URI.
name string The local name of the attribute.
Source:
Returns:
The attribute's value, or null if not present.
Type
string

getContents(elemnon-null) → {string}

Gets the text contents of a node.
Parameters:
Name Type Description
elem Node The XML element.
Source:
Returns:
The text contents, or null if there are none.
Type
string

parseAttr(elemnon-null, name, parseFunction, defaultValueopt) → {T|null}

Parses an attribute by its name.
Parameters:
Name Type Attributes Default Description
elem Element The XML element.
name string The attribute name.
parseFunction function(string): (T|null) A function that parses the attribute.
defaultValue T | null <optional>
null The attribute's default value, if not specified, the attibute's default value is null.
Source:
Returns:
The parsed attribute on success, or the attribute's default value if the attribute does not exist or could not be parsed.
Type
T | null

parseDate(dateString) → {number}

Parses an XML date string.
Parameters:
Name Type Description
dateString string
Source:
Returns:
The parsed date in seconds on success; otherwise, return null.
Type
number

parseDuration(durationString) → {number}

Parses an XML duration string. Negative values are not supported. Years and months are treated as exactly 365 and 30 days respectively.
Parameters:
Name Type Description
durationString string The duration string, e.g., "PT1H3M43.2S", which means 1 hour, 3 minutes, and 43.2 seconds.
Source:
See:
Returns:
The parsed duration in seconds on success; otherwise, return null.
Type
number

parseFloat(floatString) → {number}

Parses a floating point number.
Parameters:
Name Type Description
floatString string The floating point number string.
Source:
Returns:
The parsed floating point number on success; otherwise, return null. May return -Infinity or Infinity.
Type
number

parseInt(intString) → {number}

Parses an integer.
Parameters:
Name Type Description
intString string The integer string.
Source:
Returns:
The parsed integer on success; otherwise, return null.
Type
number

parseNonNegativeInt(intString) → {number}

Parses a non-negative integer.
Parameters:
Name Type Description
intString string The integer string.
Source:
Returns:
The parsed non-negative integer on success; otherwise, return null.
Type
number

parsePositiveInt(intString) → {number}

Parses a positive integer.
Parameters:
Name Type Description
intString string The integer string.
Source:
Returns:
The parsed positive integer on success; otherwise, return null.
Type
number

parseRange(rangeString) → {?{start: number, end: number}}

Parses a range string.
Parameters:
Name Type Description
rangeString string The range string, e.g., "101-9213".
Source:
Returns:
The parsed range on success; otherwise, return null.
Type
?{start: number, end: number}

parseXml(data, expectedRootElemName) → {Element}

Parse some UTF8 data and return the resulting root element if it was valid XML.
Parameters:
Name Type Description
data BufferSource
expectedRootElemName string
Source:
Returns:
Type
Element

parseXmlString(xmlString, expectedRootElemName) → {Element}

Parse a string and return the resulting root element if it was valid XML.
Parameters:
Name Type Description
xmlString string
expectedRootElemName string
Source:
Returns:
Type
Element