Skip to content
FutureBlitz

    Install

    Import std.data.xml

    std.data.xml

    XML 1.0: a document's tree of XmlNodes, which Xml.Read builds over an XmlReader and Xml.Write writes over an XmlWriter, and Values to and from an element, as xmltodict has them: an element's attributes are keys with '@' before their names, its children keys of their names, an Array where a name comes more than once, and its text the key "#text", or the element's Value itself, a String, when it has neither attributes nor children.

    std/data/xml.fb

    Types

    XmlKind enum

    Public Enum XmlKind

    What an XmlNode is.

    std/data/xml.fb, line 14

    • ELEMENT enum member #

      An element, with a name, attributes, and children.

    • TEXT enum member #

      Text.

    • CDATA enum member #

      A CDATA section's text.

    • COMMENT enum member #

      A comment.

    • INSTRUCTION enum member #

      A processing instruction.

    • ATTRIBUTE enum member #

      An attribute, with a name and a value.

    XmlNode 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.

    std/data/xml.fb, line 32

    • 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.

    Xml struct

    Public Struct Xml

    What reads and writes XML documents and their Values, in its Static Methods.

    std/data/xml.fb, line 198

    • Public Static Method Read(text: String): XmlNode Throws ParseError static method #

      The root element of the document text holds, its text, CDATA, comments, and processing instructions its nodes; those outside it are left out. Throws a ParseError as XmlReader's Next does.

    • @PanicsAtCaller Public Static Method Write(root: XmlNode, indent: Int = 2, declaration: Bool = True): String static method #

      root as an XML document, the XML declaration first when declaration says so. An indent above 0 puts each element on a line of its own, that many spaces in for each element it's in, but for what's in an element that holds text, whose spaces are its own, so what's written reads back as the same tree. Panics when root isn't an element, or a node holds what XML can't, as XmlWriter's Methods say.

    • Public Static Method ToValue(element: XmlNode): Value static method #

      element as a Value: an Object of its attributes, with '@' before their names, and its child elements, by name, an Array of those of a name that comes more than once, and "#text" for its text when it isn't only spaces; or its text, a String, when it has no attributes or child elements. Comments and processing instructions are left out.

    • @PanicsAtCaller Public Static Method FromValue(name: String, value: Value): XmlNode static method #

      A new element named name of value, as ToValue gives a Value: an Object's keys with '@' before them its attributes, "#text" its text, and the rest its child elements, an Array's items each a child of its key's name; another Value its text, an integer's, a Double's, or a Bool's as its text, and Null's none. Panics when name or a key isn't an XML name, an attribute's value or "#text" is an Array or an Object, an Array's item is an Array, or value is an Array.

    XmlWriter class

    Public Class XmlWriter

    XmlWriter: XML written a part at a time, each element started, given its attributes, its content written, and ended, in order, into a String that Finish gives. An indent above 0 puts each element on a line of its own, but in an element that holds text, from its first text on, as a writer that goes a part at a time can't know of text to come.

    std/data/xml.fb, line 476

    • @PanicsAtCaller Public New(indent: Int = 0) constructor #

      A writer that indents each element that many spaces for each it's in, or writes them on one line for 0. Panics when indent is negative.

    • @PanicsAtCaller Public Method Declaration() method #

      Writes <?xml version="1.0" encoding="UTF-8"?>. Panics after anything else is written.

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

      Starts an element named name. Panics when name isn't an XML name, or the root element has ended.

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

      Gives the element just started an attribute. Panics when name isn't an XML name, it isn't right after the start or another attribute, the element has an attribute of that name already, or value holds a character XML hasn't got.

    • @PanicsAtCaller Public Method Text(text: String) method #

      Writes text in the open element. Panics outside one, or when text holds a character XML hasn't got.

    • @PanicsAtCaller Public Method CData(text: String) method #

      Writes a CDATA section of text in the open element, one more each time text holds "]]>", whose "]]" ends one and '>' starts the next. Panics outside an element, or when text holds a character XML hasn't got.

    • @PanicsAtCaller Public Method Comment(text: String) method #

      Writes a comment. Panics when text holds "--", ends with '-', or holds a character XML hasn't got.

    • @PanicsAtCaller Public Method Instruction(target: String, text: String) method #

      Writes a processing instruction. Panics when target isn't an XML name or is xml, or text holds "?>" or a character XML hasn't got.

    • @PanicsAtCaller Public Method EndElement() method #

      Ends the open element, as <name/> when it's empty. Panics when none is open.

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

      What was written. Panics when an element is open, or none was written.

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