Documentation
¶
Overview ¶
Package scriptxml is the XML reading a managed script is given, as a Starlark module.
It is separate from the engine for the reason internal/scriptdate is: every function is a pure transformation of its arguments, there is no run, no caller and no state, and the engine's only use of it is to predeclare the module. The parsing itself is internal/xmltree, which api_invoke_endpoint also decodes through, so a script and a tool call read one document the same way (#1735).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = &starlarkstruct.Module{ Name: "xml", Members: starlark.StringDict{ "decode": starlark.NewBuiltin("xml.decode", xmlDecode), "encode": starlark.NewBuiltin("xml.encode", xmlEncode), "find": starlark.NewBuiltin("xml.find", xmlFind), "findall": starlark.NewBuiltin("xml.findall", xmlFindAll), }, }
Module is the XML module the engine predeclares.
The four functions are the whole of it. There is deliberately no pretty-printer, no schema validation and no namespace registry: an element's namespace is on the element, names match on their local part, and a script that needs a document rendered for a person is exporting it, not formatting it.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element is a decoded element as a script sees it: a read-only view onto one node of the tree xml.decode produced.
It is its own value type rather than a dict so that `el.tag` reads as an attribute and so xml.find can be handed a node without the caller reassembling one. Because it implements HasAttrs, json.encode renders it as an object with the same five fields, which is what lets a script hand a decoded document straight to platform.export or print it in a run log.
func (*Element) Attr ¶
Attr reads one of the element's five fields. An unknown name returns nil, which is how Starlark asks a value to report that it has no such attribute and produces the standard "has no .foo field" error.
func (*Element) Freeze ¶
func (*Element) Freeze()
Freeze is a no-op: an element is immutable whether or not it has been frozen. Nothing a script can do reaches the tree behind it — the dict and list Attr hands back are fresh values, and they are frozen there rather than here so a mutation attempt is an error at the point it is written instead of a silent write to a copy.
func (*Element) Hash ¶
Hash refuses: an element is not a dict key. Matching elements by identity would be the only available meaning and it is not one an author would want.
func (*Element) String ¶
String renders the element the way an author identifies it in a run log: the tag, and the namespace when there is one. The document itself is what xml.encode is for, so this stays short however large the subtree is.