Skip to content

Latest commit

 

History

History
1133 lines (664 loc) · 19.8 KB

File metadata and controls

1133 lines (664 loc) · 19.8 KB

@borgar/simple-xml

Classes

Type Aliases

Variables

Functions

CDataNode

A class describing an CDataNode.

Extends

Constructors

Constructor

new CDataNode(value?: string): CDataNode;

Constructs a new CDataNode instance.

Parameters

Parameter Type Default value Description
value? string '' The data for the node

Returns

CDataNode

Overrides

Node.constructor

Properties

Property Type Default value Description Inherited from
childNodes Node[] [] The node's immediate children. Node.childNodes
nodeName string '#node' A node type string identifier. Node.nodeName
nodeType number 0 A numerical node type identifier. Node.nodeType
parentNode Node | null null The node's parent node. Node.parentNode
value string undefined The nodes data value. -

Accessors

preserveSpace

Get Signature

get preserveSpace(): boolean;

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

Returns

boolean

Inherited from

Node.preserveSpace


textContent

Get Signature

get textContent(): string;

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

Returns

string

Overrides

Node.textContent

Methods

appendChild()

appendChild(node: Node): Node;

Appends a child node into the current one.

Parameters

Parameter Type Description
node Node The new child node

Returns

Node

The same node that was passed in.

Inherited from

Node.appendChild


toString()

toString(): string;

Returns a string representation of the node.

Returns

string

A formatted XML source.

Inherited from

Node.toString

Document

This class describes an XML document.

Extends

Constructors

Constructor

new Document(): Document;

Constructs a new Document instance.

Returns

Document

Overrides

Node.constructor

Properties

Property Type Default value Description Inherited from
childNodes Node[] [] The node's immediate children. Node.childNodes
nodeName string '#node' A node type string identifier. Node.nodeName
nodeType number 0 A numerical node type identifier. Node.nodeType
parentNode Node | null null The node's parent node. Node.parentNode
root Element | null null - -

Accessors

children

Get Signature

get children(): Element[];

A list containing all child Elements of the current Element.

Returns

Element[]


preserveSpace

Get Signature

get preserveSpace(): boolean;

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

Returns

boolean

Inherited from

Node.preserveSpace


textContent

Get Signature

get textContent(): string;

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

Returns

string

Overrides

Node.textContent

Methods

appendChild()

appendChild(node: Element): Element;

Appends a child node into the current one.

Parameters

Parameter Type Description
node Element The new child node

Returns

Element

The same node that was passed in.

Overrides

Node.appendChild


getElementsByTagName()

getElementsByTagName(tagName: string): Element[];

Return all descendant elements that have the specified tag name.

Parameters

Parameter Type Description
tagName string The tag name to filter by.

Returns

Element[]

The elements by tag name.


querySelector()

querySelector(selector: string): Element | null;

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

Parameters

Parameter Type Description
selector string The CSS selector to filter by.

Returns

Element | null

The elements by tag name.


querySelectorAll()

querySelectorAll(selector: string): Element[];

Return all descendant elements that match a specified CSS selector.

Parameters

Parameter Type Description
selector string The CSS selector to filter by.

Returns

Element[]

The elements by tag name.


toJS()

toJS(): [] | JsonMLElement;

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

Returns

[] | JsonMLElement

JsonML representation of the nodes and its subtree.


toString()

toString(): string;

Returns a string representation of the node.

Returns

string

A formatted XML source.

Inherited from

Node.toString

Element

A class describing an Element.

Extends

Constructors

Constructor

new Element(
   tagName: string, 
   attr?: Record<string, string>, 
   closed?: boolean): Element;

Constructs a new Element instance.

Parameters

Parameter Type Default value Description
tagName string undefined The tag name of the node.
attr? Record<string, string> {} A collection of attributes to assign.
closed? boolean false Was the element "self-closed" when read.

Returns

Element

Overrides

Node.constructor

Properties

Property Type Default value Description Overrides Inherited from
attr Record<string, string> undefined An object of attributes assigned to this element. - -
childNodes Node[] [] The node's immediate children. - Node.childNodes
closed boolean undefined A state representing if the element was "self-closed" when read. - -
fullName string undefined The full name of the tag for the given element, including a namespace prefix. - -
nodeName string '#node' A node type string identifier. - Node.nodeName
nodeType number 0 A numerical node type identifier. - Node.nodeType
ns string undefined The namespace prefix of the element, or null if no prefix is specified. - -
parentNode Element | null null The node's parent node. Node.parentNode -
tagName string undefined The name of the tag for the given element, excluding any namespace prefix. - -

Accessors

children

Get Signature

get children(): Element[];

A list containing all child Elements of the current Element.

Returns

Element[]


preserveSpace

Get Signature

get preserveSpace(): boolean;

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

Returns

boolean

Overrides

Node.preserveSpace


textContent

Get Signature

get textContent(): string;

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

Returns

string

Inherited from

Node.textContent

Methods

appendChild()

appendChild(node: Node): Node;

Appends a child node into the current one.

Parameters

Parameter Type Description
node Node The new child node

Returns

Node

The same node that was passed in.

Inherited from

Node.appendChild


getAttribute()

getAttribute(name: string): string | null;

Read an attribute from the element.

Parameters

Parameter Type Description
name string The attribute name to read.

Returns

string | null

The attribute.


getElementsByTagName()

getElementsByTagName(tagName: string): Element[];

Return all descendant elements that have the specified tag name.

Parameters

Parameter Type Description
tagName string The tag name to filter by.

Returns

Element[]

The elements by tag name.


hasAttribute()

hasAttribute(name: string): boolean;

Test if an attribute exists on the element.

Parameters

Parameter Type Description
name string The attribute name to test for.

Returns

boolean

True if the attribute is present.


querySelector()

querySelector(selector: string): Element | null;

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

Parameters

Parameter Type Description
selector string The CSS selector to filter by.

Returns

Element | null

The elements by tag name.


querySelectorAll()

querySelectorAll(selector: string): Element[];

Return all descendant elements that match a specified CSS selector.

Parameters

Parameter Type Description
selector string The CSS selector to filter by.

Returns

Element[]

The elements by tag name.


removeAttribute()

removeAttribute(name: string): void;

Remove an attribute off the element.

Parameters

Parameter Type Description
name string The attribute name to remove.

Returns

void


setAttribute()

setAttribute(name: string, value: string): void;

Sets an attribute on the element.

Parameters

Parameter Type Description
name string The attribute name to read.
value string The value to set

Returns

void


toJS()

toJS(): JsonMLElement;

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

Returns

JsonMLElement

JsonML representation of the nodes and its subtree.


toString()

toString(): string;

Returns a string representation of the node.

Returns

string

A formatted XML source.

Inherited from

Node.toString

Node

A class describing a Node.

Extended by

Constructors

Constructor

new Node(): Node;

Returns

Node

Properties

Property Type Default value Description
childNodes Node[] [] The node's immediate children.
nodeName string '#node' A node type string identifier.
nodeType number 0 A numerical node type identifier.
parentNode Node | null null The node's parent node.

Accessors

preserveSpace

Get Signature

get preserveSpace(): boolean;

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

Returns

boolean


textContent

Get Signature

get textContent(): string;

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

Returns

string

Methods

appendChild()

appendChild(node: Node): Node;

Appends a child node into the current one.

Parameters

Parameter Type Description
node Node The new child node

Returns

Node

The same node that was passed in.


toString()

toString(): string;

Returns a string representation of the node.

Returns

string

A formatted XML source.

TextNode

A class describing a TextNode.

Extends

Constructors

Constructor

new TextNode(value?: string): TextNode;

Constructs a new TextNode instance.

Parameters

Parameter Type Description
value? string The data for the node

Returns

TextNode

Overrides

Node.constructor

Properties

Property Type Default value Description Inherited from
childNodes Node[] [] The node's immediate children. Node.childNodes
nodeName string '#node' A node type string identifier. Node.nodeName
nodeType number 0 A numerical node type identifier. Node.nodeType
parentNode Node | null null The node's parent node. Node.parentNode
value string undefined The node's data value. -

Accessors

preserveSpace

Get Signature

get preserveSpace(): boolean;

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

Returns

boolean

Inherited from

Node.preserveSpace


textContent

Get Signature

get textContent(): string;

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

Returns

string

Overrides

Node.textContent

Methods

appendChild()

appendChild(node: Node): Node;

Appends a child node into the current one.

Parameters

Parameter Type Description
node Node The new child node

Returns

Node

The same node that was passed in.

Inherited from

Node.appendChild


toString()

toString(): string;

Returns a string representation of the node.

Returns

string

A formatted XML source.

Inherited from

Node.toString

parseXML()

function parseXML(source: string, options?: {
  emptyDoc?: boolean;
  laxAttr?: boolean;
}): Document;

Parse an XML source and return a Node tree.

Parameters

Parameter Type Default value Description
source string undefined The XML source to parse.
options? { emptyDoc?: boolean; laxAttr?: boolean; } DEFAULTOPTIONS Parsing options.
options.emptyDoc? boolean undefined Permit "rootless" documents.
options.laxAttr? boolean undefined Permit unquoted attributes (<node foo=bar />).

Returns

Document

A DOM representing the XML node tree.

JsonMLAttr

type JsonMLAttr = Record<string, string | number | boolean | null>;

JsonMLElement

type JsonMLElement = 
  | [string, JsonMLAttr, ...JsonMLElement[]]
  | [string, JsonMLAttr]
  | [string, ...JsonMLElement[]]
  | [string]
  | string;

ATTRIBUTE_NODE

const ATTRIBUTE_NODE: number = 2;

An attribute node identifier

CDATA_SECTION_NODE

const CDATA_SECTION_NODE: number = 4;

A CData Section node identifier

COMMENT_NODE

const COMMENT_NODE: number = 8;

A comment node identifier

DOCUMENT_FRAGMENT_NODE

const DOCUMENT_FRAGMENT_NODE: number = 11;

A document fragment node identifier

DOCUMENT_NODE

const DOCUMENT_NODE: number = 9;

A document node identifier

DOCUMENT_TYPE_NODE

const DOCUMENT_TYPE_NODE: number = 10;

A document type node identifier

ELEMENT_NODE

const ELEMENT_NODE: number = 1;

An element node identifier

ENTITY_NODE

const ENTITY_NODE: number = 6;

An entity node identifier

ENTITY_REFERENCE_NODE

const ENTITY_REFERENCE_NODE: number = 5;

An entity reference node identifier

NOTATION_NODE

const NOTATION_NODE: number = 12;

A documentation node identifier

PROCESSING_INSTRUCTION_NODE

const PROCESSING_INSTRUCTION_NODE: number = 7;

A processing instruction node identifier

TEXT_NODE

const TEXT_NODE: number = 3;

A text node identifier