std/xml
On this page
Index
- type
Name - type
Attr - type
Token - type
XmlErr- method
XmlErr.display
- method
- type
Reader- method
Reader.next
- method
- type
Element- method
Element.attr - method
Element.child - method
Element.children_named - method
Element.text - method
Element.encode
- method
- type
Node - fn
tokens - fn
raw_tokens - fn
reader - fn
raw_reader - fn
parse - fn
escape - fn
escape_to - fn
encode_value - fn
decode
Types
Name
struct Name {
space: Str
local: Str
} derive Eq, Ord, HashAn element or attribute name. space is the namespace URL once
resolved (the prefix itself in raw tokens); empty for none.
Attr
struct Attr {
name: Name
value: Str
} derive EqToken
enum Token {
Start(name: Name, attrs: List[Attr])
End(name: Name)
Text(s: Str)
Comment(s: Str)
ProcInst(target: Str, inst: Str)
Directive(s: Str)
} derive EqGo’s xml.Token.
XmlErr
struct XmlErr {
line: Int
msg: Str
}Go’s SyntaxError (line > 0): displays as XML syntax error on line N: MSG; Go’s other errors and parse’s own (line 0) as MSG.
XmlErr.display
fn (e: XmlErr) display() -> StrReader
struct Reader {}Tokens one at a time (Go’s Decoder.Token and RawToken): the same tokens as
tokens and raw_tokens, without holding the list; the input stays
(decision 0463).
Reader.next
fn (var r: Reader) next() -> Token? ! XmlErrThe next token, None at the end of the input; an error is returned again by every later call.
Element
struct Element {
name: Name
attrs: List[Attr]
children: List[Node]
} derive EqAn element and everything inside it.
Element.attr
fn (e: Element) attr(local: Str) -> Str?The value of the first attribute of that local name.
Element.child
fn (e: Element) child(local: Str) -> Element?The first child element of that local name.
Element.children_named
fn (e: Element) children_named(local: Str) -> List[Element]Element.text
fn (e: Element) text() -> StrThe character data inside e, its descendants’ included, in order.
Element.encode
fn (e: Element) encode(indent: Str = "") -> Str ! XmlErrThe element as Go’s Encoder writes its tokens (Indent("", indent) when
indent is not empty), or the Encoder’s error (xml: comment cannot contain "--").
Node
enum Node {
Elem(e: Element)
Text(s: Str)
Comment(s: Str)
ProcInst(target: Str, inst: Str)
Directive(s: Str)
Raw(s: Str)
} derive EqFunctions
tokens
fn tokens(text: Str, strict: Bool = true) -> List[Token] ! XmlErrEvery token of text (Decoder.Token until EOF). strict: false is Go’s Strict = false with AutoClose = HTMLAutoClose and Entity = HTMLEntity.
raw_tokens
fn raw_tokens(text: Str) -> List[Token] ! XmlErrDecoder.RawToken until EOF: prefixes as written, no start and end matching.
reader
fn reader(text: Str, strict: Bool = true) -> ReaderA reader of text’s tokens (tokens’s rules, strict: false as there).
raw_reader
fn raw_reader(text: Str) -> ReaderA reader of Decoder.RawToken’s tokens (raw_tokens).
parse
fn parse(text: Str, strict: Bool = true) -> Element ! XmlErrThe document’s root element; outside it only whitespace, comments,
processing instructions, and directives (xml: no root element, xml: more than one root element, xml: text outside the root element).
escape
fn escape(s: Str) -> StrGo’s EscapeText of s.
escape_to
fn escape_to(var out: StrBuilder, s: Str)Go’s EscapeText of s into out: the text escape returns, appended.
encode_value
fn encode_value[T: Xml](v: T, indent: Str = "") -> Str ! XmlErrGo’s xml.MarshalIndent of a struct that derives Xml (indent "" is
Marshal): attributes, character data, a>b>c paths, omitempty and -
from its xml wire strings (decision 0315). The call is compiled as a
call of the function derive Xml generates for T.
decode
fn decode[T: Xml](text: Str) -> T ! XmlErrGo’s xml.Unmarshal of text into a struct that derives Xml: the root element’s attributes and children by the field names, the rest ignored.
↑ index