roxmltree

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: BSD-3-Clause, MIT Imports: 10 Imported by: 3 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package roxmltree is a port of the Rust crate roxmltree 0.21.1. It represents an XML document as a read-only tree.

The root point of the package is Parse. The tree is a Document of nodes. A Node is the root, an element, a processing instruction, a comment or a text. The parser expands the entities of an internal DTD, also when the value of an entity is markup, and it resolves the namespaces (D8).

The port keeps the limits of upstream: the depth of 10 entities and the 255 references of one entity reference, the 2^16 unique namespaces, the 2^32 attributes and the nodes limit of ParsingOptions. It keeps the feature positions of upstream on, so that each node and each attribute holds its range in the input text.

Each error is a *Error that wraps a sentinel error of the root package, such as okage.ErrXMLUnknownToken (D21).

Two functions are not in upstream (D58). ParseRoot parses only up to the start tag of the root element. Builder makes a Document from the tree of another parser, without XML text. An error of a Builder is a sentinel error itself, without a position.

The parser allocates less than upstream for a large document (D105). Its guess of the number of nodes counts the text nodes, it copies a list into a list of its length only when more than a quarter of the list is spare, and one text buffer serves each text of a parse.

The tree structure itself is a heavily modified <https://github.com/causal-agent/ego-tree>, under the license ISC.

Index

Constants

View Source
const NSXMLNSURI = "http://www.w3.org/2000/xmlns/"

NSXMLNSURI is NS_XMLNS_URI in roxmltree src/lib.rs, the <http://www.w3.org/2000/xmlns/> URI.

View Source
const NSXMLURI = "http://www.w3.org/XML/1998/namespace"

NSXMLURI is NS_XML_URI in roxmltree src/lib.rs, the <http://www.w3.org/XML/1998/namespace> URI.

Variables

This section is empty.

Functions

func ToYAML

func ToYAML(doc *Document) string

ToYAML is to_yaml in roxmltree tests/ast.rs. It writes the tree of doc as the YAML text that the AST tests of upstream compare.

Types

type Attribute

type Attribute struct {
	// contains filtered or unexported fields
}

Attribute is Attribute in roxmltree src/lib.rs. It is an attribute.

func (Attribute) Equal

func (a Attribute) Equal(other Attribute) bool

Equal is PartialEq for Attribute in roxmltree src/lib.rs. Two attributes are equal when their expanded names and their values are equal.

func (Attribute) Name

func (a Attribute) Name() string

Name is Attribute::name in roxmltree src/lib.rs. It returns attribute's name.

func (Attribute) Namespace

func (a Attribute) Namespace() (string, bool)

Namespace is Attribute::namespace in roxmltree src/lib.rs. It returns attribute's namespace URI.

func (Attribute) Position deprecated

func (a Attribute) Position() int

Position is Attribute::position in roxmltree src/lib.rs. It returns attribute's position in bytes in the original document.

You can calculate a human-readable text position via Document.TextPosAt.

<e attr='value'/>
   ^

Deprecated: replaced by `range`.

func (Attribute) Range

func (a Attribute) Range() Range

Range is Attribute::range in roxmltree src/lib.rs. It returns attribute's range in bytes in the original document.

<e n:attr='value'/>
   ^^^^^^^^^^^^^^

func (Attribute) RangeQName

func (a Attribute) RangeQName() Range

RangeQName is Attribute::range_qname in roxmltree src/lib.rs. It returns attribute's qname's range in bytes in the original document.

<e n:attr='value'/>
   ^^^^^^

To reduce memory usage the qname length is limited by u16::MAX. If the attribute exceeds that limit then the end of the returned range will be incorrect.

func (Attribute) RangeValue

func (a Attribute) RangeValue() Range

RangeValue is Attribute::range_value in roxmltree src/lib.rs. It returns attribute's value's range in bytes in the original document, excluding the surrounding quotes.

If the attribute's value is an empty string then the `start` and `end` of this `Range` are equal, and indicate the closing quote.

<e n:attr='value'/>
           ^^^^^

To reduce memory usage the qname length is limited by u16::MAX, and the number of spaces around the equal sign is limited by u8::MAX. If the attribute exceeds those limits then the start of the returned range will be incorrect.

func (Attribute) String

func (a Attribute) String() string

String is fmt::Debug for Attribute in roxmltree src/lib.rs.

Port: the value prints as a quoted string. Upstream prints the StringStorage around it, such as Borrowed("b").

func (Attribute) Value

func (a Attribute) Value() string

Value is Attribute::value in roxmltree src/lib.rs. It returns attribute's value.

func (Attribute) ValueStorage

func (a Attribute) ValueStorage() string

ValueStorage is Attribute::value_storage in roxmltree src/lib.rs. It returns attribute's value storage.

Useful when you need a more low-level access to an allocated string.

Port: StringStorage is a Go string, so this is Value.

type Builder added in v0.11.0

type Builder struct {
	// contains filtered or unexported fields
}

Builder makes a Document from calls, in place of XML text (D58). A program that holds a tree from another parser, such as an HTML parser, builds a Document from it with a Builder, and needs no XML text.

Call StartElement for each element, then Namespace and Attribute for its namespace declarations and its attributes, then Text and StartElement for its content, in the order of the document, and then EndElement. Call Document at the end. The document has one root element, and no text outside it.

The names are expanded names, with the namespace URI. A Builder does not check that a name is a valid XML name, and the document keeps a name as it is. It does not declare a prefix for a namespace URI. A program that reads the prefixes, with Node.Namespaces or Node.LookupPrefix, declares them with Namespace.

The document has no input text. Its nodes and its attributes have empty ranges. An error is a sentinel error of the root package, such as okage.ErrXMLDuplicatedAttribute or okage.ErrXMLBuildOrder, without a position. After an error, each call returns the same error.

func NewBuilder added in v0.11.0

func NewBuilder(opt ParsingOptions) *Builder

NewBuilder returns a Builder of an empty document. Of the options, only NodesLimit applies, as it applies to a parse.

func (*Builder) Attribute added in v0.11.0

func (b *Builder) Attribute(name ExpandedName, value string) error

Attribute adds an attribute to the element that StartElement started.

func (*Builder) Copy added in v0.11.0

func (b *Builder) Copy(n Node) error

Copy adds a copy of the node n and of its descendants to the open element, or as the root element. For the root node of a document, it copies the children of the root node. It copies the elements, their attributes and their text. It leaves out the comments and the processing instructions. The first element that it copies declares all the namespaces in its scope, and each other element declares the namespaces that its parent does not have.

func (*Builder) Document added in v0.11.0

func (b *Builder) Document() (*Document, error)

Document returns the document. It fails when the document has no root element, or when an element is open. The builder cannot be used after it.

func (*Builder) EndElement added in v0.11.0

func (b *Builder) EndElement() error

EndElement ends the open element.

func (*Builder) Namespace added in v0.11.0

func (b *Builder) Namespace(prefix, uri string) error

Namespace declares the namespace prefix for uri on the element that StartElement started, as the attribute xmlns:prefix does. The prefix "" declares the default namespace, as the attribute xmlns does. The rules of the parser for the prefixes xml and xmlns apply.

func (*Builder) StartElement added in v0.11.0

func (b *Builder) StartElement(name ExpandedName) error

StartElement starts an element with the given name, as a child of the open element, or as the root element.

func (*Builder) Text added in v0.11.0

func (b *Builder) Text(text string) error

Text adds text to the open element. Text next to text joins it, as in a parse. An empty text adds nothing.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is Document in roxmltree src/lib.rs. It is an XML tree container.

A tree consists of [`Nodes`]. There are no separate structs for each node type. So you should check the current node type yourself via [`Node::node_type()`]. There are only [5 types](enum.NodeType.html): Root, Element, PI, Comment and Text.

As you can see there are no XML declaration and CDATA types. The XML declaration is basically skipped, since it doesn't contain any valuable information (we support only UTF-8 anyway). And CDATA will be converted into a Text node as is, without any preprocessing (you can read more about it [here](https://github.com/RazrFalcon/roxmltree/blob/master/docs/parsing.md)).

Also, the Text node data can be accessed from the text node itself or from the parent element via [`Node::text()`] or [`Node::tail()`].

func Parse

func Parse(text string) (*Document, error)

Parse is Document::parse in roxmltree src/parse.rs. It parses the input XML string.

We do not support `&[u8]` or `Reader` because the input must be an already allocated UTF-8 string.

This is a shorthand for `Document::parse_with_options(data, ParsingOptions::default())`.

Port: a Rust &str is always valid UTF-8, and the caller must check that text is, for example with utf8.ValidString. The parser reads a byte of invalid UTF-8 as U+FFFD.

func ParseRoot added in v0.11.0

func ParseRoot(text string, opt ParsingOptions) (*Document, error)

ParseRoot parses the input XML string up to the end of the start tag of the root element, and stops (D58). The document holds the nodes before the root element and the root element with its attributes and its namespaces, but no child of the root element. The parse reads the DTD, and expands its entities in the values of the attributes, as Parse does.

ParseRoot is for a program that needs only the attributes of the root element, such as the size of an SVG image. It does not check the text after the start tag, so a document that Parse rejects can give no error.

func ParseWithOptions

func ParseWithOptions(text string, opt ParsingOptions) (*Document, error)

ParseWithOptions is Document::parse_with_options in roxmltree src/parse.rs. It parses the input XML string using to selected options.

We do not support `&[u8]` or `Reader` because the input must be an already allocated UTF-8 string.

func (*Document) Descendants

func (d *Document) Descendants() iter.Seq[Node]

Descendants is Document::descendants in roxmltree src/lib.rs. It returns an iterator over document's descendant nodes.

Shorthand for `doc.root().descendants()`.

func (*Document) GetNode

func (d *Document) GetNode(id NodeID) (Node, bool)

GetNode is Document::get_node in roxmltree src/lib.rs. It returns the node of the tree with the given NodeID.

Note: NewNodeID(0) represents the root node.

func (*Document) InputText

func (d *Document) InputText() string

InputText is Document::input_text in roxmltree src/lib.rs. It returns the input text of the original document.

func (*Document) Root

func (d *Document) Root() Node

Root is Document::root in roxmltree src/lib.rs. It returns the root node.

func (*Document) RootElement

func (d *Document) RootElement() Node

RootElement is Document::root_element in roxmltree src/lib.rs. It returns the root element of the document.

Unlike `root`, will return a first element node.

The root element always exists.

func (*Document) String

func (d *Document) String() string

String is fmt::Debug for Document in roxmltree src/lib.rs.

Port: an attribute value and a namespace URI print as a quoted string. Upstream prints the StringStorage around it, such as Borrowed("b").

func (*Document) TextPosAt

func (d *Document) TextPosAt(pos int) TextPos

TextPosAt is Document::text_pos_at in roxmltree src/lib.rs. It calculates `TextPos` in the original document from position in bytes.

**Note:** this operation is expensive.

type EntityResolver

type EntityResolver func(pubID string, hasPubID bool, uri string) (value string, ok bool, err error)

EntityResolver is EntityResolver in roxmltree src/parse.rs. It is a function to resolve external entities.

This function is passed the optional public ID and the mandatory URI of the external entity.

It is expected to yield the content defining the URI, possibly preceded by a text declaration.

If it yields [`None`], the entity is discarded and will yield errors if referenced during parsing.

Errors must be stringified so they can be propagated via [`Error::EntityResolver`].

Port: hasPubID is false when the public ID is None. The function returns ok false for None. A non-nil error becomes okage.ErrXMLEntityResolver.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is Error in roxmltree src/parse.rs. It is one of all possible errors.

Port: each case of the Rust enum is a sentinel error of the root package okage, such as okage.ErrXMLUnknownToken (D21). Error wraps that sentinel error with the data of the case, so errors.Is finds the case and errors.As finds the position. The message is "parsing xml: " and the Display text of upstream. Message gives the Display text alone.

func (*Error) Error

func (e *Error) Error() string

Error satisfies the error interface. The message is "parsing xml: " and the Display text of upstream (D21).

func (*Error) Message

func (e *Error) Message() string

Message is core::fmt::Display for Error in roxmltree src/parse.rs. It returns the text that upstream displays.

func (*Error) Pos

func (e *Error) Pos() TextPos

Pos is Error::pos in roxmltree src/parse.rs. It returns the error position.

func (*Error) Unwrap

func (e *Error) Unwrap() []error

Unwrap returns the sentinel error of the case, and the error of the entity resolver for EntityResolver.

type ExpandedName

type ExpandedName struct {
	// contains filtered or unexported fields
}

ExpandedName is ExpandedName in roxmltree src/lib.rs. It is an expanded name.

Contains an namespace URI and name pair.

Port: hasURI is false when the URI is None. A URI can be Some(""), for xmlns="". Two values are equal with ==, as the PartialEq of upstream says.

func ExpandedNameFromStatic

func ExpandedNameFromStatic(uri, name string) ExpandedName

ExpandedNameFromStatic is ExpandedName::from_static in roxmltree src/lib.rs. It creates a new instance from static data.

func ExpandedNameFromStr

func ExpandedNameFromStr(v string) ExpandedName

ExpandedNameFromStr is From<&str> for ExpandedName in roxmltree src/lib.rs. The name has no namespace.

func ExpandedNameFromTuple

func ExpandedNameFromTuple(uri, name string) ExpandedName

ExpandedNameFromTuple is From<(&str, &str)> for ExpandedName in roxmltree src/lib.rs. The name has the namespace URI uri.

func (ExpandedName) Name

func (e ExpandedName) Name() string

Name is ExpandedName::name in roxmltree src/lib.rs. It returns a local name.

func (ExpandedName) Namespace

func (e ExpandedName) Namespace() (string, bool)

Namespace is ExpandedName::namespace in roxmltree src/lib.rs. It returns a namespace URI.

func (ExpandedName) String

func (e ExpandedName) String() string

String is fmt::Debug for ExpandedName in roxmltree src/lib.rs.

type Namespace

type Namespace struct {
	// contains filtered or unexported fields
}

Namespace is Namespace in roxmltree src/lib.rs. It is a namespace.

Contains URI and *prefix* pair.

Port: name is the Rust Option<&str>, and an empty name is None. Upstream never stores Some("").

func (Namespace) Name

func (n Namespace) Name() (string, bool)

Name is Namespace::name in roxmltree src/lib.rs. It returns namespace name/prefix.

func (Namespace) String

func (n Namespace) String() string

String is the derived fmt::Debug for Namespace in roxmltree src/lib.rs.

Port: the URI prints as a quoted string. Upstream prints the StringStorage around it, such as Borrowed("b").

func (Namespace) URI

func (n Namespace) URI() string

URI is Namespace::uri in roxmltree src/lib.rs. It returns namespace URI.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is Node in roxmltree src/lib.rs. It is a node in a document.

Document Order

The implementation of the `Ord` traits for `Node` is based on the concept of *document-order*. In layman's terms, document-order is the order in which one would see each element if one opened a document in a text editor or web browser and scrolled down. Document-order convention is followed in XPath, CSS Counters, and DOM selectors API to ensure consistent results from selection. One difference in `roxmltree` is that there is the notion of more than one document in existence at a time. While Nodes within the same document are in document-order, Nodes in different documents will be grouped together, but not in any particular order.

As an example, if we have a Document `a` with Nodes `[a0, a1, a2]` and a Document `b` with Nodes `[b0, b1]`, these Nodes in order could be either `[a0, a1, a2, b0, b1]` or `[b0, b1, a0, a1, a2]` and roxmltree makes no guarantee which it will be.

Document-order is defined here in the [W3C XPath Recommendation](https://www.w3.org/TR/xpath-3/#id-document-order) The use of document-order in DOM Selectors is described here in the [W3C Selectors API Level 1](https://www.w3.org/TR/selectors-api/#the-apis)

Port: two nodes are equal with ==, as the PartialEq of upstream says, and Cmp is the Ord of upstream.

func (Node) Ancestors

func (n Node) Ancestors() iter.Seq[Node]

Ancestors is Node::ancestors in roxmltree src/lib.rs. It returns an iterator over ancestor nodes starting at this node.

func (Node) Attribute

func (n Node) Attribute(name ExpandedName) (string, bool)

Attribute is Node::attribute in roxmltree src/lib.rs. It returns element's attribute value.

func (Node) AttributeNode

func (n Node) AttributeNode(name ExpandedName) (Attribute, bool)

AttributeNode is Node::attribute_node in roxmltree src/lib.rs. It returns element's attribute object.

The same as [`attribute()`], but returns the `Attribute` itself instead of a value string.

func (Node) Attributes

func (n Node) Attributes() iter.Seq[Attribute]

Attributes is Node::attributes in roxmltree src/lib.rs, with Attributes::new and the Iterator of Attributes. It returns element's attributes.

Port: upstream also gives a double ended iterator with a length. A caller that needs them collects the sequence.

func (Node) Children

func (n Node) Children() iter.Seq[Node]

Children is Node::children in roxmltree src/lib.rs, with the Iterator of Children. It returns an iterator over children nodes.

Port: upstream also gives a double ended iterator. A caller that needs it collects the sequence.

func (Node) Cmp

func (n Node) Cmp(other Node) int

Cmp is Ord for Node in roxmltree src/lib.rs. It orders the nodes by their id, then by their document.

func (Node) DefaultNamespace

func (n Node) DefaultNamespace() (string, bool)

DefaultNamespace is Node::default_namespace in roxmltree src/lib.rs. It returns node's default namespace URI.

func (Node) Descendants

func (n Node) Descendants() iter.Seq[Node]

Descendants is Node::descendants in roxmltree src/lib.rs, with Descendants::new and the Iterator of Descendants. It returns an iterator over this node and its descendants.

Port: upstream also gives a double ended iterator with a length. A caller that needs them collects the sequence.

func (Node) Document

func (n Node) Document() *Document

Document is Node::document in roxmltree src/lib.rs. It returns node's document.

func (Node) FirstChild

func (n Node) FirstChild() (Node, bool)

FirstChild is Node::first_child in roxmltree src/lib.rs. It returns the first child of this node.

func (Node) FirstChildren

func (n Node) FirstChildren() iter.Seq[Node]

FirstChildren is Node::first_children in roxmltree src/lib.rs. It returns an iterator over first children nodes starting at this node.

func (Node) FirstElementChild

func (n Node) FirstElementChild() (Node, bool)

FirstElementChild is Node::first_element_child in roxmltree src/lib.rs. It returns the first element child of this node.

func (Node) HasAttribute

func (n Node) HasAttribute(name ExpandedName) bool

HasAttribute is Node::has_attribute in roxmltree src/lib.rs. It checks that element has a specified attribute.

func (Node) HasChildren

func (n Node) HasChildren() bool

HasChildren is Node::has_children in roxmltree src/lib.rs. It returns true if this node has children.

func (Node) HasSiblings

func (n Node) HasSiblings() bool

HasSiblings is Node::has_siblings in roxmltree src/lib.rs. It returns true if this node has siblings.

func (Node) HasTagName

func (n Node) HasTagName(name ExpandedName) bool

HasTagName is Node::has_tag_name in roxmltree src/lib.rs. It checks that node has a specified tag name.

func (Node) ID

func (n Node) ID() NodeID

ID is Node::id in roxmltree src/lib.rs. It returns node's NodeID.

func (Node) IsComment

func (n Node) IsComment() bool

IsComment is Node::is_comment in roxmltree src/lib.rs. It checks that node is a comment node.

func (Node) IsElement

func (n Node) IsElement() bool

IsElement is Node::is_element in roxmltree src/lib.rs. It checks that node is an element node.

func (Node) IsPI

func (n Node) IsPI() bool

IsPI is Node::is_pi in roxmltree src/lib.rs. It checks that node is a processing instruction node.

func (Node) IsRoot

func (n Node) IsRoot() bool

IsRoot is Node::is_root in roxmltree src/lib.rs. It checks that node is a root node.

func (Node) IsText

func (n Node) IsText() bool

IsText is Node::is_text in roxmltree src/lib.rs. It checks that node is a text node.

func (Node) LastChild

func (n Node) LastChild() (Node, bool)

LastChild is Node::last_child in roxmltree src/lib.rs. It returns the last child of this node.

func (Node) LastChildren

func (n Node) LastChildren() iter.Seq[Node]

LastChildren is Node::last_children in roxmltree src/lib.rs. It returns an iterator over last children nodes starting at this node.

func (Node) LastElementChild

func (n Node) LastElementChild() (Node, bool)

LastElementChild is Node::last_element_child in roxmltree src/lib.rs. It returns the last element child of this node.

Port: upstream walks the children from the back. Go walks them from the front and keeps the last element, which gives the same node.

func (Node) LookupNamespaceURI

func (n Node) LookupNamespaceURI(prefix string) (string, bool)

LookupNamespaceURI is Node::lookup_namespace_uri in roxmltree src/lib.rs. It returns an URI for a given prefix.

Port: an empty prefix is None. Upstream returns None for Some(""), and Go returns the default namespace for "".

func (Node) LookupPrefix

func (n Node) LookupPrefix(uri string) (string, bool)

LookupPrefix is Node::lookup_prefix in roxmltree src/lib.rs. It returns a prefix for a given namespace URI.

func (Node) Namespaces

func (n Node) Namespaces() iter.Seq[Namespace]

Namespaces is Node::namespaces in roxmltree src/lib.rs, with the Iterator of NamespaceIter. It returns element's namespaces.

Port: upstream also gives a double ended iterator with a length. A caller that needs them collects the sequence. The next_back of upstream returns the next item from the front, and Go has no port of it.

func (Node) NextSibling

func (n Node) NextSibling() (Node, bool)

NextSibling is Node::next_sibling in roxmltree src/lib.rs. It returns the next sibling of this node.

func (Node) NextSiblingElement

func (n Node) NextSiblingElement() (Node, bool)

NextSiblingElement is Node::next_sibling_element in roxmltree src/lib.rs. It returns the next sibling element of this node.

func (Node) NextSiblings

func (n Node) NextSiblings() iter.Seq[Node]

NextSiblings is Node::next_siblings in roxmltree src/lib.rs. It returns an iterator over next sibling nodes starting at this node.

func (Node) NodeType

func (n Node) NodeType() NodeType

NodeType is Node::node_type in roxmltree src/lib.rs. It returns node's type.

func (Node) PI

func (n Node) PI() (PI, bool)

PI is Node::pi in roxmltree src/lib.rs. It returns node as Processing Instruction.

func (Node) Parent

func (n Node) Parent() (Node, bool)

Parent is Node::parent in roxmltree src/lib.rs. It returns the parent of this node.

func (Node) ParentElement

func (n Node) ParentElement() (Node, bool)

ParentElement is Node::parent_element in roxmltree src/lib.rs. It returns the parent element of this node.

func (Node) PrevSibling

func (n Node) PrevSibling() (Node, bool)

PrevSibling is Node::prev_sibling in roxmltree src/lib.rs. It returns the previous sibling of this node.

func (Node) PrevSiblingElement

func (n Node) PrevSiblingElement() (Node, bool)

PrevSiblingElement is Node::prev_sibling_element in roxmltree src/lib.rs. It returns the previous sibling element of this node.

func (Node) PrevSiblings

func (n Node) PrevSiblings() iter.Seq[Node]

PrevSiblings is Node::prev_siblings in roxmltree src/lib.rs. It returns an iterator over previous sibling nodes starting at this node.

func (Node) Range

func (n Node) Range() Range

Range is Node::range in roxmltree src/lib.rs. It returns node's range in bytes in the original document.

func (Node) String

func (n Node) String() string

String is fmt::Debug for Node in roxmltree src/lib.rs.

Port: the attributes and the namespaces of an element print as a list of their own Debug texts. Upstream prints the slice iterators that hold them.

func (Node) TagName

func (n Node) TagName() ExpandedName

TagName is Node::tag_name in roxmltree src/lib.rs. It returns node's tag name.

Returns an empty name with no namespace if the current node is not an element.

func (Node) Tail

func (n Node) Tail() (string, bool)

Tail is Node::tail in roxmltree src/lib.rs. It returns element's tail text.

func (Node) TailStorage

func (n Node) TailStorage() (string, bool)

TailStorage is Node::tail_storage in roxmltree src/lib.rs. It returns element's tail text storage.

Useful when you need a more low-level access to an allocated string.

Port: StringStorage is a Go string, so this is Tail.

func (Node) Text

func (n Node) Text() (string, bool)

Text is Node::text in roxmltree src/lib.rs. It returns node's text.

  • for an element will return a first text child
  • for a comment will return a self text
  • for a text node will return a self text

func (Node) TextStorage

func (n Node) TextStorage() (string, bool)

TextStorage is Node::text_storage in roxmltree src/lib.rs. It returns node's text storage.

Useful when you need a more low-level access to an allocated string.

Port: StringStorage is a Go string, so this is Text.

type NodeID

type NodeID uint32

NodeID is NodeId in roxmltree src/lib.rs. It is a node ID stored as `u32`.

An index into a `Tree`-internal `Vec`.

Note that this value should be used with care since `roxmltree` doesn't check that `NodeId` actually belongs to a selected `Document`. So you can end up in a situation, when `NodeId` produced by one `Document` is used to select a node in another `Document`.

Port: upstream stores id+1 in a NonZeroU32, so that Option<NodeId> is small. NodeID holds the id itself, and optNodeID holds id+1 for the fields of a node.

func NewNodeID

func NewNodeID(id uint32) NodeID

NewNodeID is NodeId::new in roxmltree src/lib.rs. It constructs a new `NodeId` from a `u32`.

func (NodeID) Get

func (id NodeID) Get() uint32

Get is NodeId::get in roxmltree src/lib.rs. It returns the `u32` representation of the `NodeId`.

func (NodeID) GetUsize

func (id NodeID) GetUsize() int

GetUsize is NodeId::get_usize in roxmltree src/lib.rs. It returns the `usize` representation of the `NodeId`.

type NodeType

type NodeType uint8

NodeType is NodeType in roxmltree src/lib.rs. It is a list of supported node types.

const (
	// NodeTypeRoot is the root node of the `Document`.
	NodeTypeRoot NodeType = iota
	// NodeTypeElement is an element node.
	//
	// Only an element can have a tag name and attributes.
	NodeTypeElement
	// NodeTypePI is a processing instruction.
	NodeTypePI
	// NodeTypeComment is a comment node.
	NodeTypeComment
	// NodeTypeText is a text node.
	NodeTypeText
)

The node types.

func (NodeType) String

func (t NodeType) String() string

String is fmt::Debug for NodeType in roxmltree src/lib.rs.

type PI

type PI struct {
	Target string
	Value  string
}

PI is PI in roxmltree src/lib.rs. It is a processing instruction.

Port: Value is the Rust Option<&str>, and an empty Value is None. The tokenizer never gives Some(""), so no value is lost.

type ParsingOptions

type ParsingOptions struct {
	// Allow DTD parsing.
	//
	// When set to `false`, XML with DTD will cause an error.
	// Empty DTD block is not an error.
	//
	// Currently, there is no option to simply skip DTD.
	// Mainly because you will get `UnknownEntityReference` error later anyway.
	//
	// This flag is set to `false` by default for security reasons,
	// but `roxmltree` still has checks for billion laughs attack,
	// so this is just an extra security measure.
	//
	// Default: false
	AllowDTD bool

	// Sets the maximum number of nodes to parse.
	//
	// Useful when dealing with random input to limit memory usage.
	//
	// Default: u32::MAX (no limit)
	NodesLimit uint32

	// Function to resolve external entities
	//
	// See [`EntityResolver`] for the signature
	// and the expected behaviour.
	//
	// Default: nil (None)
	EntityResolver EntityResolver
}

ParsingOptions is ParsingOptions in roxmltree src/parse.rs. It holds the parsing options.

Port: the zero value is not the default of upstream, because NodesLimit is zero in it. Start from DefaultParsingOptions.

func DefaultParsingOptions

func DefaultParsingOptions() ParsingOptions

DefaultParsingOptions is Default for ParsingOptions in roxmltree src/parse.rs.

func (ParsingOptions) String

func (o ParsingOptions) String() string

String is fmt::Debug for ParsingOptions in roxmltree src/parse.rs.

type Range

type Range struct {
	Start int
	End   int
}

Range is core::ops::Range<usize> of the Rust core library: the byte offsets from Start to End, with End excluded.

type TextPos

type TextPos struct {
	Row uint32
	Col uint32
}

TextPos is TextPos in roxmltree src/lib.rs. It is a position in text.

Position indicates a row/line and a column in the original text. Starting from 1:1.

func NewTextPos

func NewTextPos(row, col uint32) TextPos

NewTextPos is TextPos::new in roxmltree src/lib.rs. It constructs a new `TextPos`.

func (TextPos) String

func (p TextPos) String() string

String is fmt::Display for TextPos in roxmltree src/lib.rs.

Jump to

Keyboard shortcuts

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