std/xmlcodec
On this page
Index
- type
Piece - type
Writer - type
Event - fn
open_path - fn
leaf - fn
child - fn
chardata - fn
comment - fn
attr - fn
build - fn
writer - fn
write_start - fn
write_open - fn
write_leaf - fn
write_chardata - fn
write_end - fn
written - fn
parse_root - fn
attr_of - fn
events - fn
direct_text - fn
float_text - fn
int_of - fn
float_of - fn
bool_of
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.
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.
Event
struct Event {
field: Int
el: xml.Element
}An element of a field’s path (an index of paths), found in document
order.
Functions
open_path
fn open_path(parents: List[Str]) -> PieceOpens the path a field’s parents name (Go pushes them even for an empty list).
leaf
fn leaf(parents: List[Str], name: Str, text: Str) -> PieceA child element name holding the text.
child
fn child(parents: List[Str], name: Str, el: xml.Element) -> PieceA child element: the tree of a nested struct, named name.
chardata
fn chardata(text: Str) -> PieceCharacter data inside the open element.
comment
fn comment(text: Str) -> PieceA comment inside the open element.
attr
fn attr(name: Str, value: Str) -> xml.AttrAn attribute.
build
fn build(name: Str, attrs: List[xml.Attr], pieces: List[Piece]) -> xml.ElementThe element name with the attributes and, in order, the pieces
(Go’s printer: parents shared with the previous field stay open).
writer
fn writer(indent: Str) -> WriterA writer that indents by indent (none when empty).
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).
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.
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).
write_chardata
fn write_chardata(var w: Writer, text: Str)Character data where the writer is (chardata’s piece).
write_end
fn write_end(var w: Writer, name: Str)Closes the open parents and the element name write_start began.
written
fn written(var w: Writer) -> StrThe text written.
parse_root
fn parse_root(text: Str) -> xml.Element ! xml.XmlErrThe root element of text, as Go’s Unmarshal finds it: a text with no
element is EOF.
attr_of
fn attr_of(e: xml.Element, name: Str) -> Str?The value of the attribute of that local name.
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.
direct_text
fn direct_text(e: xml.Element) -> StrThe character data directly inside e, in order (Go’s chardata).
float_text
fn float_text(f: Float) -> StrGo’s FormatFloat(f, ‘g’, -1, 64): Xo’s text of a Float without the “.0” an integral value gets.
int_of
fn int_of(s: Str) -> Int ! xml.XmlErrGo’s strconv.ParseInt of the text with spaces trimmed (0 when empty):
strconv.ParseInt: parsing "x": invalid syntax or value out of range.
float_of
fn float_of(s: Str) -> Float ! xml.XmlErrGo’s strconv.ParseFloat of the text with spaces trimmed (0 when
empty): strconv.ParseFloat: parsing "x": invalid syntax or value out of range.
bool_of
fn bool_of(s: Str) -> Bool ! xml.XmlErrGo’s strconv.ParseBool (false when empty).
↑ index