Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · xml

Docs

std/xml

On this page

Index

Types

Name

struct Name {
  space: Str
  local: Str
} derive Eq, Ord, Hash

An element or attribute name. space is the namespace URL once resolved (the prefix itself in raw tokens); empty for none.

Source: std/xml.xo:9

Attr

struct Attr {
  name: Name
  value: Str
} derive Eq

Source: std/xml.xo:14

Token

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 Eq

Go’s xml.Token.

Source: std/xml.xo:20

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.

Source: std/xml.xo:32

XmlErr.display

fn (e: XmlErr) display() -> Str

Source: std/xml.xo:37

Reader

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

Source: std/xml.xo:49

Reader.next

fn (var r: Reader) next() -> Token? ! XmlErr

The next token, None at the end of the input; an error is returned again by every later call.

Source: std/xml.xo:57

Element

struct Element {
  name: Name
  attrs: List[Attr]
  children: List[Node]
} derive Eq

An element and everything inside it.

Source: std/xml.xo:60

Element.attr

fn (e: Element) attr(local: Str) -> Str?

The value of the first attribute of that local name.

Source: std/xml.xo:82

Element.child

fn (e: Element) child(local: Str) -> Element?

The first child element of that local name.

Source: std/xml.xo:84

Element.children_named

fn (e: Element) children_named(local: Str) -> List[Element]

Source: std/xml.xo:85

Element.text

fn (e: Element) text() -> Str

The character data inside e, its descendants’ included, in order.

Source: std/xml.xo:87

Element.encode

fn (e: Element) encode(indent: Str = "") -> Str ! XmlErr

The element as Go’s Encoder writes its tokens (Indent("", indent) when indent is not empty), or the Encoder’s error (xml: comment cannot contain "--").

Source: std/xml.xo:91

Node

enum Node {
  Elem(e: Element)
  Text(s: Str)
  Comment(s: Str)
  ProcInst(target: Str, inst: Str)
  Directive(s: Str)
  Raw(s: Str)
} derive Eq

Source: std/xml.xo:66

Functions

tokens

fn tokens(text: Str, strict: Bool = true) -> List[Token] ! XmlErr

Every token of text (Decoder.Token until EOF). strict: false is Go’s Strict = false with AutoClose = HTMLAutoClose and Entity = HTMLEntity.

Source: std/xml.xo:41

raw_tokens

fn raw_tokens(text: Str) -> List[Token] ! XmlErr

Decoder.RawToken until EOF: prefixes as written, no start and end matching.

Source: std/xml.xo:44

reader

fn reader(text: Str, strict: Bool = true) -> Reader

A reader of text’s tokens (tokens’s rules, strict: false as there).

Source: std/xml.xo:52

raw_reader

fn raw_reader(text: Str) -> Reader

A reader of Decoder.RawToken’s tokens (raw_tokens).

Source: std/xml.xo:54

parse

fn parse(text: Str, strict: Bool = true) -> Element ! XmlErr

The 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).

Source: std/xml.xo:80

escape

fn escape(s: Str) -> Str

Go’s EscapeText of s.

Source: std/xml.xo:93

escape_to

fn escape_to(var out: StrBuilder, s: Str)

Go’s EscapeText of s into out: the text escape returns, appended.

Source: std/xml.xo:95

encode_value

fn encode_value[T: Xml](v: T, indent: Str = "") -> Str ! XmlErr

Go’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.

Source: std/xml.xo:101

decode

fn decode[T: Xml](text: Str) -> T ! XmlErr

Go’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.

Source: std/xml.xo:104

↑ index