Import std.data.xml
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")-
The root element of the document
textholds, 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): Stringstatic method #rootas an XML document, the XML declaration first whendeclarationsays 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 whenrootisn't an element, or a node holds what XML can't, as XmlWriter's Methods say. -
elementas 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") -
A new element named
nameofvalue, 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 whennameor 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, orvalueis an Array.
Report an issue with this page or with FutureBlitz on GitHub.