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.
-
An element, with a name, attributes, and children.
-
Text.
-
A CDATA section's text.
-
A comment.
-
A processing instruction.
-
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.
-
Whether it's an element, text, CDATA, a comment, a processing instruction, or an attribute.
-
An element's or attribute's name, or a processing instruction's target.
-
The text of text, CDATA, a comment, or a processing instruction, or an attribute's value.
-
An element's attributes, by name, in order.
-
An element's children, in order.
-
A new element named
name. Panics whennameisn't an XML name. -
A node of
text. -
A CDATA section of
text. -
A comment of
text. -
@PanicsAtCaller Public Static Method NewInstruction(target: String, text: String): XmlNodestatic method #A processing instruction for
target. Panics whentargetisn't an XML name. -
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.
-
An element's attribute's value, or Null when it has none of that
name. -
Gives an element's attribute a value, adding it at the end when it's new. Panics when
nameisn't an XML name. -
An element's first child element named
name, or Null. -
An element's child elements, in order, or those named
namewhen it isn't "". -
Adds
childat the end of an element's children, and gives it. -
Adds a new element named
name, and gives it. Panics whennameisn't an XML name. -
Adds
textat the end of an element's children. -
The nodes
pathselects, from this one, in the document's order: XmlPath's subset of XPath 1.0. Panics whenpathisn't one XmlPath reads. -
The first node
pathselects, or Null when it selects none. Panics as Query does. -
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.
-
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. -
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.
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.
-
A writer that indents each element that many spaces for each it's in, or writes them on one line for 0. Panics when
indentis negative. -
Writes
<?xml version="1.0" encoding="UTF-8"?>. Panics after anything else is written. -
Starts an element named
name. Panics whennameisn't an XML name, or the root element has ended. -
Gives the element just started an attribute. Panics when
nameisn't an XML name, it isn't right after the start or another attribute, the element has an attribute of thatnamealready, orvalueholds a character XML hasn't got. -
Writes
textin the open element. Panics outside one, or whentextholds a character XML hasn't got. -
Writes a CDATA section of
textin the open element, one more each timetextholds "]]>", whose "]]" ends one and '>' starts the next. Panics outside an element, or whentextholds a character XML hasn't got. -
Writes a comment. Panics when
textholds "--", ends with '-', or holds a character XML hasn't got. -
Writes a processing instruction. Panics when
targetisn't an XML name or is xml, ortextholds "?>" or a character XML hasn't got. -
Ends the open element, as
<name/>when it's empty. Panics when none is open. -
What was written. Panics when an element is open, or none was written.
Report an issue with this page or with FutureBlitz on GitHub.