Options
All
  • Public
  • Public/Protected
  • All
Menu

Class XmlElement

Represents an XML element.

A sample XML element is structured as follows, where {name} is the name of the element:

<{name} attname="attvalue">
    <subelem/>
    <?pitarget picontent?>
    text
</{name}></pre>

The {name} value is a property of the node, while the attributes and children of the element (such as other elements, processing instructions, and text) are children of this node.

XmlElement nodes can have an unlimited number of XmlAttribute, XmlCdata, XmlCharRef, XmlComment, XmlElement, XmlEntityRef, XmlProcInst, or XmlCharData nodes as children.

Hierarchy

Index

Constructors

constructor

Properties

Protected _children

_children: XmlNode[]

Private _name

_name: string

Accessors

name

  • get name(): string
  • set name(name: string): void
  • Gets the name of the element.

    Returns string

    The name of the element.

  • Sets the name of the element.

    Parameters

    • name: string

      The name of the element.

    Returns void

    The name of the element.

parent

  • get parent(): XmlNode | undefined
  • Gets the parent of this node.

    Returns XmlNode | undefined

    The parent of this node.

Methods

attribute

  • Inserts an new attribute at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • name: string

      The name of the attribute.

    • value: string | XmlNode | Array<string | XmlNode>

      The value of the attribute. Strings are converted to XmlAttributeText nodes.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlAttribute

    The newly created attribute.

attributes

  • Returns an array containing all of the children of this node that are instances of XmlAttribute.

    Returns XmlAttribute[]

    An array containing all of the children of this node that are instances of XmlAttribute.

cdata

  • cdata(content: string, index?: number): XmlCdata
  • Inserts a new CDATA section at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • content: string

      The data of the CDATA section.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlCdata

    The newly created CDATA section.

charData

  • charData(charData: string, index?: number): XmlCharData
  • Inserts some character data at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • charData: string

      Character data.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlCharData

    The newly created text node.

charRef

  • charRef(char: string, hex?: boolean, index?: number): XmlCharRef
  • Inserts a new character reference at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • char: string

      The character to represent using the reference.

    • Optional hex: boolean

      Whether to use the hexadecimal or decimal representation for the reference. If left undefined, decimal is the default.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlCharRef

    The newly created character reference.

children

  • Gets this node's children.

    Throws an exception if this node cannot have any children. Consult the appropriate subclass documentation for more details.

    Returns XmlNode[]

    This node's children.

comment

  • comment(content: string, index?: number): XmlComment
  • Inserts a new comment at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • content: string

      The data of the comment.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlComment

    The newly created comment.

element

  • element(name: string, index?: number): XmlElement
  • Inserts a new element at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • name: string

      The name of the element.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlElement

    The newly created element.

entityRef

  • Inserts a new entity reference at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • entity: string

      The entity to be referenced.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlEntityRef

    The newly created entity reference.

insertChild

  • Inserts the specified node into this node's children at the specified index. The node is not inserted if it is already present. If this node already has a parent, it is removed from that parent.

    Note that only XmlAttribute, XmlCdata, XmlCharRef, XmlComment, XmlElement, XmlEntityRef, XmlProcInst, or XmlCharData nodes can be inserted; otherwise, an exception will be thrown.

    Parameters

    • node: XmlNode

      The node to insert.

    • Optional index: number

      The index at which to insert the node. Nodes at or after the index are shifted to the right. If no index is specified, the node is inserted at the end.

    Returns XmlNode | undefined

    The node inserted into this node's children, or undefined if no node was inserted.

next

  • Gets the node that follows this one, or undefined if no such node exists or if this node has no parent.

    Returns XmlNode | undefined

    The node that follows this one, or undefined if no such node exists or if this node has no parent.

prev

  • Gets the node that is previous to this one, or undefined if no such node exists or if this node has no parent.

    Returns XmlNode | undefined

    The node that is previous to this one, or undefined if no such node exists or if this node has no parent.

procInst

  • procInst(target: string, content?: string, index?: number): XmlProcInst
  • Inserts a new processing instruction at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • target: string

      The target of the processing instruction.

    • Optional content: string

      The data of the processing instruction, or undefined if there is no target.

    • Optional index: number

      The index at which the node should be inserted. If no index is specified, the node is inserted at the end of this node's children.

    Returns XmlProcInst

    The newly created processing instruction.

remove

  • Removes this node from its parent if this node has a parent.

    Returns XmlNode | undefined

    This node's parent, or undefined if it has no parent.

removeChild

  • removeChild(node: XmlNode): boolean
  • Removes the specified node from this node's children.

    Throws an exception if this node cannot have any children, or if the specified node cannot be removed. Consult the appropriate subclass documentation for more details.

    Parameters

    • node: XmlNode

      The node to remove.

    Returns boolean

    Whether a node was removed.

removeChildAtIndex

  • removeChildAtIndex(index: number): XmlNode
  • Removes the node at the specified index from this node's children.

    Throws an exception if this node cannot have any children, or if the node at the specified index cannot be removed. Consult the appropriate subclass documentation for more details.

    Parameters

    • index: number

      The index at which the node to be removed is located.

    Returns XmlNode

    The node that was removed.

toString

  • Returns an XML string representation of this node.

    Parameters

    • Default value options: IStringOptions = {}

      Formatting options for the string representation.

    Returns string

    An XML string representation of this node.

top

  • Returns the root node of the current hierarchy. If this node has no parent, this node itself is returned.

    Returns XmlNode

    The root node of the current hierarchy.

up

  • Gets the parent of this node.

    Returns XmlNode | undefined

Generated using TypeDoc