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
- func ToYAML(doc *Document) string
- type Attribute
- func (a Attribute) Equal(other Attribute) bool
- func (a Attribute) Name() string
- func (a Attribute) Namespace() (string, bool)
- func (a Attribute) Position() intdeprecated
- func (a Attribute) Range() Range
- func (a Attribute) RangeQName() Range
- func (a Attribute) RangeValue() Range
- func (a Attribute) String() string
- func (a Attribute) Value() string
- func (a Attribute) ValueStorage() string
- type Builder
- func (b *Builder) Attribute(name ExpandedName, value string) error
- func (b *Builder) Copy(n Node) error
- func (b *Builder) Document() (*Document, error)
- func (b *Builder) EndElement() error
- func (b *Builder) Namespace(prefix, uri string) error
- func (b *Builder) StartElement(name ExpandedName) error
- func (b *Builder) Text(text string) error
- type Document
- type EntityResolver
- type Error
- type ExpandedName
- type Namespace
- type Node
- func (n Node) Ancestors() iter.Seq[Node]
- func (n Node) Attribute(name ExpandedName) (string, bool)
- func (n Node) AttributeNode(name ExpandedName) (Attribute, bool)
- func (n Node) Attributes() iter.Seq[Attribute]
- func (n Node) Children() iter.Seq[Node]
- func (n Node) Cmp(other Node) int
- func (n Node) DefaultNamespace() (string, bool)
- func (n Node) Descendants() iter.Seq[Node]
- func (n Node) Document() *Document
- func (n Node) FirstChild() (Node, bool)
- func (n Node) FirstChildren() iter.Seq[Node]
- func (n Node) FirstElementChild() (Node, bool)
- func (n Node) HasAttribute(name ExpandedName) bool
- func (n Node) HasChildren() bool
- func (n Node) HasSiblings() bool
- func (n Node) HasTagName(name ExpandedName) bool
- func (n Node) ID() NodeID
- func (n Node) IsComment() bool
- func (n Node) IsElement() bool
- func (n Node) IsPI() bool
- func (n Node) IsRoot() bool
- func (n Node) IsText() bool
- func (n Node) LastChild() (Node, bool)
- func (n Node) LastChildren() iter.Seq[Node]
- func (n Node) LastElementChild() (Node, bool)
- func (n Node) LookupNamespaceURI(prefix string) (string, bool)
- func (n Node) LookupPrefix(uri string) (string, bool)
- func (n Node) Namespaces() iter.Seq[Namespace]
- func (n Node) NextSibling() (Node, bool)
- func (n Node) NextSiblingElement() (Node, bool)
- func (n Node) NextSiblings() iter.Seq[Node]
- func (n Node) NodeType() NodeType
- func (n Node) PI() (PI, bool)
- func (n Node) Parent() (Node, bool)
- func (n Node) ParentElement() (Node, bool)
- func (n Node) PrevSibling() (Node, bool)
- func (n Node) PrevSiblingElement() (Node, bool)
- func (n Node) PrevSiblings() iter.Seq[Node]
- func (n Node) Range() Range
- func (n Node) String() string
- func (n Node) TagName() ExpandedName
- func (n Node) Tail() (string, bool)
- func (n Node) TailStorage() (string, bool)
- func (n Node) Text() (string, bool)
- func (n Node) TextStorage() (string, bool)
- type NodeID
- type NodeType
- type PI
- type ParsingOptions
- type Range
- type TextPos
Constants ¶
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.
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 ¶
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 ¶
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 ¶
Name is Attribute::name in roxmltree src/lib.rs. It returns attribute's name.
func (Attribute) Namespace ¶
Namespace is Attribute::namespace in roxmltree src/lib.rs. It returns attribute's namespace URI.
func (Attribute) Position
deprecated
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Value is Attribute::value in roxmltree src/lib.rs. It returns attribute's value.
func (Attribute) ValueStorage ¶
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
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
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
EndElement ends the open element.
func (*Builder) Namespace ¶ added in v0.11.0
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.
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 ¶
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 ¶
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 ¶
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 ¶
InputText is Document::input_text in roxmltree src/lib.rs. It returns the input text of the original document.
func (*Document) RootElement ¶
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.
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 ¶
Error satisfies the error interface. The message is "parsing xml: " and the Display text of upstream (D21).
func (*Error) Message ¶
Message is core::fmt::Display for Error in roxmltree src/parse.rs. It returns the text that upstream displays.
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 ¶
Name is Namespace::name in roxmltree src/lib.rs. It returns namespace name/prefix.
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 ¶
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 ¶
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 ¶
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 ¶
Cmp is Ord for Node in roxmltree src/lib.rs. It orders the nodes by their id, then by their document.
func (Node) DefaultNamespace ¶
DefaultNamespace is Node::default_namespace in roxmltree src/lib.rs. It returns node's default namespace URI.
func (Node) Descendants ¶
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 ¶
Document is Node::document in roxmltree src/lib.rs. It returns node's document.
func (Node) FirstChild ¶
FirstChild is Node::first_child in roxmltree src/lib.rs. It returns the first child of this node.
func (Node) FirstChildren ¶
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 ¶
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 ¶
HasChildren is Node::has_children in roxmltree src/lib.rs. It returns true if this node has children.
func (Node) HasSiblings ¶
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) IsComment ¶
IsComment is Node::is_comment in roxmltree src/lib.rs. It checks that node is a comment node.
func (Node) IsElement ¶
IsElement is Node::is_element in roxmltree src/lib.rs. It checks that node is an element node.
func (Node) IsPI ¶
IsPI is Node::is_pi in roxmltree src/lib.rs. It checks that node is a processing instruction node.
func (Node) IsRoot ¶
IsRoot is Node::is_root in roxmltree src/lib.rs. It checks that node is a root node.
func (Node) IsText ¶
IsText is Node::is_text in roxmltree src/lib.rs. It checks that node is a text node.
func (Node) LastChild ¶
LastChild is Node::last_child in roxmltree src/lib.rs. It returns the last child of this node.
func (Node) LastChildren ¶
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 ¶
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 ¶
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 ¶
LookupPrefix is Node::lookup_prefix in roxmltree src/lib.rs. It returns a prefix for a given namespace URI.
func (Node) Namespaces ¶
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 ¶
NextSibling is Node::next_sibling in roxmltree src/lib.rs. It returns the next sibling of this node.
func (Node) NextSiblingElement ¶
NextSiblingElement is Node::next_sibling_element in roxmltree src/lib.rs. It returns the next sibling element of this node.
func (Node) NextSiblings ¶
NextSiblings is Node::next_siblings in roxmltree src/lib.rs. It returns an iterator over next sibling nodes starting at this node.
func (Node) Parent ¶
Parent is Node::parent in roxmltree src/lib.rs. It returns the parent of this node.
func (Node) ParentElement ¶
ParentElement is Node::parent_element in roxmltree src/lib.rs. It returns the parent element of this node.
func (Node) PrevSibling ¶
PrevSibling is Node::prev_sibling in roxmltree src/lib.rs. It returns the previous sibling of this node.
func (Node) PrevSiblingElement ¶
PrevSiblingElement is Node::prev_sibling_element in roxmltree src/lib.rs. It returns the previous sibling element of this node.
func (Node) PrevSiblings ¶
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 ¶
Range is Node::range in roxmltree src/lib.rs. It returns node's range in bytes in the original document.
func (Node) 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) TailStorage ¶
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 ¶
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 ¶
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 ¶
NewNodeID is NodeId::new in roxmltree src/lib.rs. It constructs a new `NodeId` from a `u32`.
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.
type PI ¶
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 ¶
Range is core::ops::Range<usize> of the Rust core library: the byte offsets from Start to End, with End excluded.
type TextPos ¶
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 ¶
NewTextPos is TextPos::new in roxmltree src/lib.rs. It constructs a new `TextPos`.