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

Docs

std/xmlcodec

On this page

Index

Types

Piece

struct Piece {
  parents: List[Str]
  kind: Int
  name: Str = ""
  text: Str = ""
  el: xml.Element? = None
}

One part of a struct’s element: its parents path (the a>b of a field’s name, empty for none), and what to write there.

Source: std/xmlcodec.xo:12

Writer

struct Writer {
  out: StrBuilder
  indent: Str
  depth: Int = 0
  indented_in: Bool = false
  put_newline: Bool = false
  names: List[Str] = []
  bases: List[Int] = []
}

The text of elements written in order, as Element.encode writes the tree build makes of the same pieces (Go’s printer and its parent stack), with no tree: write_start an element, then its fields' write_open, write_leaf and write_chardata and nested starts, then write_end it. Names and attributes have no namespace.

Source: std/xmlcodec.xo:44

Event

struct Event {
  field: Int
  el: xml.Element
}

An element of a field’s path (an index of paths), found in document order.

Source: std/xmlcodec.xo:80

Functions

open_path

fn open_path(parents: List[Str]) -> Piece

Opens the path a field’s parents name (Go pushes them even for an empty list).

Source: std/xmlcodec.xo:24

leaf

fn leaf(parents: List[Str], name: Str, text: Str) -> Piece

A child element name holding the text.

Source: std/xmlcodec.xo:26

child

fn child(parents: List[Str], name: Str, el: xml.Element) -> Piece

A child element: the tree of a nested struct, named name.

Source: std/xmlcodec.xo:28

chardata

fn chardata(text: Str) -> Piece

Character data inside the open element.

Source: std/xmlcodec.xo:30

comment

fn comment(text: Str) -> Piece

A comment inside the open element.

Source: std/xmlcodec.xo:32

attr

fn attr(name: Str, value: Str) -> xml.Attr

An attribute.

Source: std/xmlcodec.xo:34

build

fn build(name: Str, attrs: List[xml.Attr], pieces: List[Piece]) -> xml.Element

The element name with the attributes and, in order, the pieces (Go’s printer: parents shared with the previous field stay open).

Source: std/xmlcodec.xo:37

writer

fn writer(indent: Str) -> Writer

A writer that indents by indent (none when empty).

Source: std/xmlcodec.xo:57

write_start

fn write_start(var w: Writer, name: Str, attrs: List[xml.Attr])

Starts element name with the attributes (an empty local name is left out).

Source: std/xmlcodec.xo:60

write_open

fn write_open(var w: Writer, parents: List[Str])

Opens the path parents in the started element (open_path’s piece): the parents the previous field opened stay open as far as they match.

Source: std/xmlcodec.xo:63

write_leaf

fn write_leaf(var w: Writer, parents: List[Str], name: Str, text: Str)

The element name holding the text under parents (leaf’s piece).

Source: std/xmlcodec.xo:65

write_chardata

fn write_chardata(var w: Writer, text: Str)

Character data where the writer is (chardata’s piece).

Source: std/xmlcodec.xo:67

write_end

fn write_end(var w: Writer, name: Str)

Closes the open parents and the element name write_start began.

Source: std/xmlcodec.xo:69

written

fn written(var w: Writer) -> Str

The text written.

Source: std/xmlcodec.xo:71

parse_root

fn parse_root(text: Str) -> xml.Element ! xml.XmlErr

The root element of text, as Go’s Unmarshal finds it: a text with no element is EOF.

Source: std/xmlcodec.xo:75

attr_of

fn attr_of(e: xml.Element, name: Str) -> Str?

The value of the attribute of that local name.

Source: std/xmlcodec.xo:77

events

fn events(e: xml.Element, paths: List[List[Str]]) -> List[Event]

The elements below e whose path from e is one of paths, in document order, with the index of the path.

Source: std/xmlcodec.xo:87

direct_text

fn direct_text(e: xml.Element) -> Str

The character data directly inside e, in order (Go’s chardata).

Source: std/xmlcodec.xo:89

float_text

fn float_text(f: Float) -> Str

Go’s FormatFloat(f, ‘g’, -1, 64): Xo’s text of a Float without the “.0” an integral value gets.

Source: std/xmlcodec.xo:93

int_of

fn int_of(s: Str) -> Int ! xml.XmlErr

Go’s strconv.ParseInt of the text with spaces trimmed (0 when empty): strconv.ParseInt: parsing "x": invalid syntax or value out of range.

Source: std/xmlcodec.xo:97

float_of

fn float_of(s: Str) -> Float ! xml.XmlErr

Go’s strconv.ParseFloat of the text with spaces trimmed (0 when empty): strconv.ParseFloat: parsing "x": invalid syntax or value out of range.

Source: std/xmlcodec.xo:101

bool_of

fn bool_of(s: Str) -> Bool ! xml.XmlErr

Go’s strconv.ParseBool (false when empty).

Source: std/xmlcodec.xo:103

↑ index