Skip to content

Latest commit

 

History

History
803 lines (463 loc) · 20.1 KB

API.md

File metadata and controls

803 lines (463 loc) · 20.1 KB

Simple-xml API

Classes

Function

Constants

Classes

# CDataNode( [value = ""] ) extends Node

A class describing an CDataNode.


# .constructor( [value = ""] )

Constructs a new CDataNode instance.

Parameters
Name Type Default Description
[value] string "" The data for the node

# .appendChild( node ) ⇒ Node

Appends a child node into the current one.

Parameters
Name Type Description
node Node The new child node
Returns

Node – The same node that was passed in.


# .childNodes

The node's children.


# .nodeName

A node type string identifier.


# .nodeType

A numerical node type identifier.


# .parentNode

The node's parent node.


# .preserveSpace

True if xml:space has been set to true for this node or any of its ancestors.


# .textContent

The text content of this node (and its children).


# .toString() ⇒ string

Returns a string representation of the node.

Returns

string – A formatted XML source.


# .value

The nodes data value.


# Document() extends Node

This class describes an XML document.


# .appendChild( node ) ⇒ Node

Appends a child node into the current one.

Parameters
Name Type Description
node Node The new child node
Returns

Node – The same node that was passed in.


# .childNodes

The node's children.


# .children() ⇒ void

A list containing all child Elements of the current Element.


# .getElementsByTagName( tagName ) ⇒ Array<Element>

Return all descendant elements that have the specified tag name.

Parameters
Name Type Description
tagName string The tag name to filter by.
Returns

Array<Element> – The elements by tag name.


# .nodeName

A node type string identifier.


# .nodeType

A numerical node type identifier.


# .parentNode

The node's parent node.


# .preserveSpace

True if xml:space has been set to true for this node or any of its ancestors.


# .querySelector( selector ) ⇒ Element | null

Return the first descendant element that match a specified CSS selector.

Parameters
Name Type Description
selector string The CSS selector to filter by.
Returns

Element | null – The elements by tag name.


# .querySelectorAll( selector ) ⇒ Array<Element>

Return all descendant elements that match a specified CSS selector.

Parameters
Name Type Description
selector string The CSS selector to filter by.
Returns

Array<Element> – The elements by tag name.


# .textContent

The text content of this node (and its children).


# .toJS() ⇒ Array<any> | null

Returns a simple object representation of the node and its descendants.

Returns

Array<any> | null – JsonML representation of the nodes and its subtree.


# .toString() ⇒ string

Returns a string representation of the node.

Returns

string – A formatted XML source.


# Element( tagName, [attr = {}, closed] ) extends Node

A class describing an Element.


# .constructor( tagName, [attr = {}, closed] )

Constructs a new Element instance.

Parameters
Name Type Default Description
tagName string The tag name of the node.
[attr] object {} A collection of attributes to assign.
[closed] boolean false Was the element "self-closed" when read.

# .appendChild( node ) ⇒ Node

Appends a child node into the current one.

Parameters
Name Type Description
node Node The new child node
Returns

Node – The same node that was passed in.


# .attr

An object of attributes assigned to this element.


# .childNodes

The node's children.


# .children() ⇒ void

A list containing all child Elements of the current Element.


# .closed

A state representing if the element was "self-closed" when read.


# .fullName

The full name of the tag for the given element, including a namespace prefix.


# .getAttribute( name ) ⇒ string | null

Read an attribute from the element.

Parameters
Name Type Description
name string The attribute name to read.
Returns

string | null – The attribute.


# .getElementsByTagName( tagName ) ⇒ Array<Element>

Return all descendant elements that have the specified tag name.

Parameters
Name Type Description
tagName string The tag name to filter by.
Returns

Array<Element> – The elements by tag name.


# .hasAttribute( name ) ⇒ boolean

Test if an attribute exists on the element.

Parameters
Name Type Description
name string The attribute name to test for.
Returns

boolean – True if the attribute is present.


# .nodeName

A node type string identifier.


# .nodeType

A numerical node type identifier.


# .ns

The namespace prefix of the element, or null if no prefix is specified.


# .parentNode

The node's parent node.


# .preserveSpace

True if xml:space has been set to true for this node or any of its ancestors.


# .querySelector( selector ) ⇒ Element | null

Return the first descendant element that match a specified CSS selector.

Parameters
Name Type Description
selector string The CSS selector to filter by.
Returns

Element | null – The elements by tag name.


# .querySelectorAll( selector ) ⇒ Array<Element>

Return all descendant elements that match a specified CSS selector.

Parameters
Name Type Description
selector string The CSS selector to filter by.
Returns

Array<Element> – The elements by tag name.


# .removeAttribute( name ) ⇒ void

Remove an attribute off the element.

Parameters
Name Type Description
name string The attribute name to remove.

# .setAttribute( name, value ) ⇒ void

Sets an attribute on the element.

Parameters
Name Type Description
name string The attribute name to read.
value string The value to set

# .tagName

The name of the tag for the given element, excluding any namespace prefix.


# .textContent

The text content of this node (and its children).


# .toJS() ⇒ Array<any> | string

Returns a simple object representation of the node and its descendants.

Returns

Array<any> | string – JsonML representation of the nodes and its subtree.


# .toString() ⇒ string

Returns a string representation of the node.

Returns

string – A formatted XML source.


# Node()

A class describing a Node.


# .constructor()

Constructs a new Node instance.


# .appendChild( node ) ⇒ Node

Appends a child node into the current one.

Parameters
Name Type Description
node Node The new child node
Returns

Node – The same node that was passed in.


# .childNodes

The node's children.


# .nodeName

A node type string identifier.


# .nodeType

A numerical node type identifier.


# .parentNode

The node's parent node.


# .preserveSpace() ⇒ void

True if xml:space has been set to true for this node or any of its ancestors.


# .textContent() ⇒ void

The text content of this node (and its children).


# .toString() ⇒ string

Returns a string representation of the node.

Returns

string – A formatted XML source.


# TextNode( [value = ""] ) extends Node

A class describing a TextNode.


# .constructor( [value = ""] )

Constructs a new TextNode instance.

Parameters
Name Type Default Description
[value] string "" The data for the node

# .appendChild( node ) ⇒ Node

Appends a child node into the current one.

Parameters
Name Type Description
node Node The new child node
Returns

Node – The same node that was passed in.


# .childNodes

The node's children.


# .nodeName

A node type string identifier.


# .nodeType

A numerical node type identifier.


# .parentNode

The node's parent node.


# .preserveSpace

True if xml:space has been set to true for this node or any of its ancestors.


# .textContent

The text content of this node (and its children).


# .toString() ⇒ string

Returns a string representation of the node.

Returns

string – A formatted XML source.


# .value

The node's data value.


Function

# parseXML( source, [options = {}] ) ⇒ Document

Parse an XML source and return a Node tree.

Parameters
Name Type Default Description
source string The XML source to parse.
[options] object {} Parsing options.
[options].emptyDoc boolean false Permit "rootless" documents.
[options].laxAttr boolean false Permit unquoted attributes (<node foo=bar />).
Returns

Document – A DOM representing the XML node tree.


Constants

# ATTRIBUTE_NODE = number

An attribute node identifier


# CDATA_SECTION_NODE = number

A CData Section node identifier


# COMMENT_NODE = number

A comment node identifier


# DOCUMENT_FRAGMENT_NODE = number

A document fragment node identifier


# DOCUMENT_NODE = number

A document node identifier


# DOCUMENT_TYPE_NODE = number

A document type node identifier


# ELEMENT_NODE = number

An element node identifier


# ENTITY_NODE = number

An entity node identifier


# ENTITY_REFERENCE_NODE = number

An entity reference node identifier


# NOTATION_NODE = number

A documentation node identifier


# PROCESSING_INSTRUCTION_NODE = number

A processing instruction node identifier


# TEXT_NODE = number

A text node identifier