Represents an XML element.

Hierarchy

Constructors

  • Initializes a new XElement instance with the specified name.

    Parameters

    • name: string | XName

      The name of the element.

    • Rest ...contentArray: any[]

      Zero or more content items.

    Returns XElement

  • Initializes a new instance of the XElement class from another XElement object.

    Parameters

    • other: XElement

      Another element that will be copied to this element.

    Returns XElement

Properties

emptySequence: Iterable<XElement> = ...

Gets an empty collection of elements.

Accessors

  • Gets the XDocument object for this XObject.

    Returns null | XDocument

  • Gets the first attribute of this element.

    Returns null | XAttribute

  • get firstNode(): null | XNode
  • Gets this container's first XNode or null, if this container does not have any nodes.

    Returns null | XNode

  • get hasAttributes(): boolean
  • Gets a value indicating whether the element has at least one attribute.

    Returns boolean

  • get hasElements(): boolean
  • Gets a value indicating whether the element has at least one child element.

    Returns boolean

  • get isEmpty(): boolean
  • Gets a value indicating whether the element contains no content.

    Returns boolean

  • Gets the last attribute of this element.

    Returns null | XAttribute

  • get lastNode(): null | XNode
  • Gets this container's last XNode or null, if this container does not have any nodes.

    Returns null | XNode

  • Gets the name of this element.

    Returns XName

  • Sets the name of this element.

    Parameters

    Returns void

  • get nextNode(): null | XNode
  • Gets the next sibling node of this node.

    If this node does not have a parent, or if there is no next node, then this property returns null.

    Returns null | XNode

  • Gets the parent XElement of this XObject.

    Returns null | XElement

  • get previousNode(): null | XNode
  • Gets the previous sibling node of this node.

    If this property does not have a parent, or if there is no previous node, then this property returns null.

    Returns null | XNode

  • get value(): string
  • set value(content: string): void
  • Gets the text contents of this element.

    If there is text content interspersed with nodes (mixed content) then the text content will be concatenated and returned.

    Returns string

  • Sets the text content of this element.

    Parameters

    • content: string

    Returns void

Methods

  • add(content: any): void
  • Adds the specified content as a child (or children) of this XContainer.

    Parameters

    • content: any

      A content object containing simple content or a collection of content objects to be added.

    Returns void

  • Returns the collection of the ancestor elements for this node.

    Returns

    The ancestor elements of this node.

    Parameters

    • Optional name: null | XName

      The optional name of the ancestor elements to find.

    Returns LinqElements

  • Returns this XElement and all of it's ancestors up to the root node. Optionally, an XName can be passed in to target specific ancestors.

    Returns

    An iterable containing this XElement and its ancestors (with a matching XName if name was provided).

    Parameters

    • Optional name: null | XName

      The optional XName of the target ancestor.

    Returns LinqElements

  • Returns the XAttribute associated with this XElement that has the given name.

    Returns

    The XAttribute having the given XName or null.

    Parameters

    • name: XName

      The XName of the XAttribute to get.

    Returns null | XAttribute

  • Gets all attributes associated with this element or the attribute having the given name.

    Returns

    All attributes associated with this element or the attribute having the given name.

    Parameters

    • Optional name: null | XName

      The name of the attribute to return.

    Returns LinqAttributes

  • Gets the descendant XElements of this XContainer.

    Returns

    The descendant XElements of this XContainer.

    Parameters

    • Optional name: null | XName

      The optional name of the descendants to return.

    Returns LinqElements

  • Gets this XElement and the descendant XElements of this XElement.

    Returns

    This XElement and the descendant XElements of this XElement.

    Parameters

    • Optional name: null | XName

      The optional name of the descendants to return.

    Returns LinqElements

  • Gets the child XElements of this XContainer.

    Returns

    The child XElements of this XContainer.

    Parameters

    • Optional name: null | XName

      The optional name of the elements to return.

    Returns LinqElements

  • Returns the default XNamespace of this XElement.

    Returns

    The default XNamespace of this XElement.

    Returns XNamespace

  • getNamespaceOfPrefix(prefix: string): null | XNamespace
  • Get the namespace associated with a particular prefix for this XElement in its document context.

    Returns

    The XNamespace for the namespace bound to the prefix.

    Throws

    If the prefix is falsy, e.g., the empty string.

    Parameters

    • prefix: string

      The namespace prefix to look up.

    Returns null | XNamespace

  • getPrefixOfNamespace(ns: XNamespace): null | string
  • Get the prefix associated with a namespace for an element in its context.

    Returns

    The namespace prefix string.

    Parameters

    • ns: XNamespace

      The XNamespace for which to get the prefix.

    Returns null | string

  • Returns the content of this XContainer. Note that the content does not include XAttributes.

    Returns

    The content of this XContainer as an IterableOfXNode.

    Returns LinqNodes

  • remove(): void
  • Removes this XNode from the underlying XML tree.

    Returns void

  • removeAll(): void
  • Removes all nodes and attributes from this XElement.

    Returns void

  • removeAttributes(): void
  • Removes all attributes from this XElement.

    Returns void

  • removeNodes(): void
  • Removes the nodes from this XContainer. Note that this method does not remove the attributes.

    Returns void

  • replaceNodes(...content: any[]): void
  • Replaces the child nodes of this XContainer with the specified content. The content can be simple content, a collection of content objects, a param list of content objects, or null.

    Parameters

    • Rest ...content: any[]

      The new content.

    Returns void

  • replaceWith(...content: any[]): void
  • Replaces this node with the specified content.

    Parameters

    • Rest ...content: any[]

      Content that replaces this node.

    Returns void

  • toString(): string
  • Returns a string that represents the current object.

    Returns

    A string that represents the current object.

    Returns string

  • Creates a new XElement instance from the given DOM Element.

    Returns

    A new XElement instance.

    Parameters

    • element: Element

      The DOM Element.

    Returns XElement

  • Creates a new XElement instance from the given XML string.

    Returns

    A new XElement instance.

    Throws

    An ArgumentException if the XML is malformed or does not contain a root element.

    Parameters

    • text: string

      The XML string.

    Returns XElement

Generated using TypeDoc