Class: shaka.util.XmlUtils

A set of XML utility functions.

Methods

(static) evalDivision(exprString) → (nullable) {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

(static) 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

(static) findChildren(elemnon-null, name) → (non-null) {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>

(static) findChildrenNS(elemnon-null, ns, name) → (non-null) {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>

(static) getAttributeNS(elemnon-null, ns, name) → (nullable) {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

(static) getContents(elemnon-null) → (nullable) {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

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

Parses an attribute by its name.
Parameters:
Name Type Attributes 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>
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

(static) parseDate(dateString) → (nullable) {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

(static) parseDuration(durationString) → (nullable) {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

(static) parseFloat(floatString) → (nullable) {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

(static) parseInt(intString) → (nullable) {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

(static) parseNonNegativeInt(intString) → (nullable) {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

(static) parsePositiveInt(intString) → (nullable) {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

(static) parseRange(rangeString) → (nullable) {?{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}