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 XmlText 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

  • Gets the parent of this node.

    Returns XmlNode

    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 | string | XmlNode
         The value of the attribute. Strings are converted to XmlText
         nodes.
      
    • Optional index: number

    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

    Returns XmlCdata

    The newly created CDATA section.

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
    • Optional index: number

    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

    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

    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

    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 XmlText nodes can be inserted; otherwise, an exception will be thrown.

    Parameters

    • node: XmlNode

      The node to insert.

    • Optional index: number

    Returns XmlNode

    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

    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

    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
    • Optional index: number

    Returns XmlProcInst

    The newly created processing instruction.

remove

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

    Returns XmlNode

    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, or undefined if no node was removed.

text

  • text(text: string, index?: number): XmlText
  • Inserts some new text at the specified index. If no index is specified, the node is inserted at the end of this node's children.

    Parameters

    • text: string

      Arbitrary character data.

    • Optional index: number

    Returns XmlText

    The newly created text node.

toString

  • Returns an XML string representation of this node.

    Parameters

    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

    The parent of this node.

Generated using TypeDoc