Element

Element

XML Element, like <foo/>.

Constructor

new Element(name, attribsopt, nsopt)

Description:
  • Creates an instance of Element.
Source:
Parameters:
Name Type Attributes Default Description
name string | Pieces If a string, the local name.
attribs Array.<AttributePair> <optional>
[] List of name/value pairs for attributes.
ns Array.<Array.<string>> <optional>
[] List of prefix/URI pairs for namespaces that are declared in this element.

Extends

Classes

Element

Members

children :Array.<Node>

Source:
Overrides:
Type:

Methods

add(node) → {Node}

Description:
  • Add a child node. Side effect: sets the parent of the added node.
Source:
Overrides:
Parameters:
Name Type Description
node Node The node to add
Returns:
The added node
Type
Node

attr(local, nsopt) → {string|undefined}

Description:
  • Find the value of an attribute that matches the given local name and namespace.
Source:
Parameters:
Name Type Attributes Description
local string the local name to search for
ns string <optional>
the namespace to search for. If not given, match attributes in any namespace.
Returns:
Attribute, if one that matches is found
Type
string | undefined

(generator) descendantElements() → {Generator.<Element>}

Description:
  • Iterate over all of the descendants of this node which are Elements, to infinite depth, in prefix order. That is, parents are yielded before their children.
Source:
Overrides:
Returns:
Type
Generator.<Element>

(generator) descendants() → {Generator.<Node>}

Description:
  • Iterate over all of the descendants of this node, to infinite depth, in prefix order. That is, parents are yielded before their children.
Source:
Overrides:
Returns:
Type
Generator.<Node>

element(local, nsopt) → {Element|undefined}

Description:
  • Find a direct child element of the given local name and namespace.
Source:
Parameters:
Name Type Attributes Description
local string The local name to search for
ns string <optional>
The namespace URI. If none given, match elements in any namespace.
Returns:
The first matching element, if one is found.
Type
Element | undefined

(generator) elements(localopt, nsopt) → {Generator.<Element>}

Description:
  • Iterate over all of the children of this Node which are Elements and match the given local name and namespace (if specified).
Source:
Overrides:
Parameters:
Name Type Attributes Description
local string <optional>
The localname. If not given, match elements with any name
ns string <optional>
The namespace URI to match. If not given, match elements with any namespace.
Returns:
Type
Generator.<Element>

removeAttribute(name) → {Attribute|null}

Description:
  • Remove an attribute.
Source:
Parameters:
Name Type Description
name string | Pieces The name of the attribute to return
Returns:
The removed attribute, if one was found
Type
Attribute | null

setAttribute(name, value) → {Attribute}

Description:
  • Set an attribute value for an attribute that might or might not exist yet.
Source:
Parameters:
Name Type Description
name string | Pieces The attribute name to set. If a string, use it as a local name in the global namespace.
value string The value to set.
Returns:
the new/modified Attribute
Type
Attribute

text(newTextopt) → {string|Node}

Description:
  • Get or set the text contained in this element. If setting, replaces all other existing children.
Source:
Overrides:
Parameters:
Name Type Attributes Description
newText string <optional>
If given, set the text of the element. Otherwise, gets all descendant text, concatenated together.
Returns:
Text on set, string on get.
Type
string | Node

toString(optionsopt) → {string}

Description:
  • Convert to string.
Source:
Overrides:
Parameters:
Name Type Attributes Description
options MaybeStylizedSeparated <optional>
How to convert to string
Returns:
The node, converted to a string
Type
string