Skip to content
FutureBlitz

    Install

    Import std.data.xml

    Xml

    std.data.xml

    struct

    Public Struct Xml

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

    Examples

    Local library = Try Xml.Read(r"""
        <library>
          <book year="1843">Notes</book>
          <book year="1952">A compiler</book>
        </library>
        """)
    Expect(library.Name == "library")
    Expect(library.Elements("book").Count == 2)
    Expect(library.Element("book")?.Attribute("year") == "1843")
    Expect(library.QueryFirst("book[@year='1952']")?.Text == "A compiler")

    std/data/xml.fb, line 225

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

      Examples

      Local book = Try Xml.Read("<book year=\"1843\"><title>Notes</title></book>")
      Local value = Xml.ToValue(book)
      Expect(value["@year"]?.AsString() == "1843")
      Expect(value["title"]?.AsString() == "Notes")
    • @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.

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