scriptxml

package
v1.132.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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

func (e *Element) Attr(name string) (starlark.Value, error)

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

func (*Element) AttrNames() []string

AttrNames lists the element's readable attributes.

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

func (e *Element) Hash() (uint32, error)

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

func (e *Element) String() 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.

func (*Element) Truth

func (*Element) Truth() starlark.Bool

Truth reports an element as true, so `if xml.find(...)` distinguishes a match from the None returned for no match rather than from an empty element.

func (*Element) Type

func (*Element) Type() string

Type is the name an error message calls this value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL