Skip to content
FutureBlitz

    Install

    Import std.data.xml

    XmlNode

    std.data.xml

    class

    Public Class XmlNode Implements Printable

    A node of an XML tree: an element, with a Name, Attributes, and Children; text, CDATA, or a comment, with its Content; a processing instruction, with its target as its Name and its Content; or an attribute, with its Name and value as its Content, as XmlPath selects one.

    Examples

    Local note = XmlNode("note")
    note.SetAttribute("lang", "en")
    note.AddElement("to").AddText("Ada")
    Expect("{note}" == "<note lang=\"en\"><to>Ada</to></note>")
    Expect(note.Element("to")?.Text == "Ada")

    std/data/xml.fb, line 44

    • Public ReadOnly Field Kind: XmlKind field #

      Whether it's an element, text, CDATA, a comment, a processing instruction, or an attribute.

    • Public Field Name: String field #

      An element's or attribute's name, or a processing instruction's target.

    • Public Field Content: String field #

      The text of text, CDATA, a comment, or a processing instruction, or an attribute's value.

    • Public ReadOnly Field Attributes: Map<String, String> field #

      An element's attributes, by name, in order.

    • Public ReadOnly Field Children: XmlNode[] field #

      An element's children, in order.

    • @PanicsAtCaller Public New(name: String) constructor #

      A new element named name. Panics when name isn't an XML name.

    • Public Static Method NewText(text: String): XmlNode static method #

      A node of text.

    • Public Static Method NewCData(text: String): XmlNode static method #

      A CDATA section of text.

    • Public Static Method NewComment(text: String): XmlNode static method #

      A comment of text.

    • @PanicsAtCaller Public Static Method NewInstruction(target: String, text: String): XmlNode static method #

      A processing instruction for target. Panics when target isn't an XML name.

    • Public Property Text: String property #

      Its text, as XPath's string() has it: an element's text and CDATA's, and its children's, in order; and another node's Content.

    • Public Method Attribute(name: String): String? method #

      An element's attribute's value, or Null when it has none of that name.

    • @PanicsAtCaller Public Method SetAttribute(name: String, value: String) method #

      Gives an element's attribute a value, adding it at the end when it's new. Panics when name isn't an XML name.

    • Public Method Element(name: String): XmlNode? method #

      An element's first child element named name, or Null.

    • Public Method Elements(name: String = ""): XmlNode[] method #

      An element's child elements, in order, or those named name when it isn't "".

    • Public Method Add(child: XmlNode): XmlNode method #

      Adds child at the end of an element's children, and gives it.

    • @PanicsAtCaller Public Method AddElement(name: String): XmlNode method #

      Adds a new element named name, and gives it. Panics when name isn't an XML name.

    • Public Method AddText(text: String) method #

      Adds text at the end of an element's children.

    • @PanicsAtCaller Public Method Query(path: String): XmlNode[] method #

      The nodes path selects, from this one, in the document's order: XmlPath's subset of XPath 1.0. Panics when path isn't one XmlPath reads.

    • @PanicsAtCaller Public Method QueryFirst(path: String): XmlNode? method #

      The first node path selects, or Null when it selects none. Panics as Query does.

    • @PanicsAtCaller Public Method ToString(): String method #

      As XML, on one line: an element as Xml.Write writes it without the declaration, text with its '&', '<', and '>' escaped, a CDATA section, a comment, a processing instruction, or an attribute as name="value". Panics as Xml.Write does, at a node that holds what XML can't.

    Report an issue with this page or with FutureBlitz on GitHub.