Expand description
XPath 1.0 over any document tree that implements Tree, written
from the W3C recommendation: every axis, node test and function of the
core library, with the number, string and boolean rules of sections 3
and 4.
With the default html feature, parsec-web’s Document is a
Tree, read as lxml reads an HTML page, which is what scrapers
expect: element and attribute names are the parser’s lowercase ones
(SVG’s clippath, viewbox) in no namespace, so //div and @href
match, //DIV and @HREF don’t, and a prefixed name (svg:rect)
matches nothing. An XML document built into the same tree is read
through XmlTree, which takes its namespaces from the host. In XML,
names with a prefix take theirs from the prefixes a query is run with.
A query reads the document through an Index, which its owner
builds once per version of the tree. Functions beyond the core library
come from the caller through Extensions.
Shadow roots are left out, as document.evaluate leaves them out: the
XPath data model has no shadow trees, so the axes follow the node tree
and never cross into a host’s shadow root or out of one. A shadow tree
is queried on its own by indexing its root as one of Index::build’s
roots, where it’s a root node as a template’s contents are: / from
inside it is the shadow root, and its host isn’t an ancestor.
Structs§
- Args
- The arguments of a call to an extension function, worked out when asked for, as the core library’s are.
- Attr
- An attribute as XPath’s data model has it.
- Doc
- The document a query runs over: its tree and the tree’s index.
- Index
- The index of one version of a tree. Its owner builds it once and keeps it until the tree changes: every query reads it, none builds it.
- NoExtensions
- No functions beyond the core library.
- XPath
- A compiled XPath expression. It holds no state of any document, so one can be shared by many threads.
- XPath
Error - XmlTree
- An XML document built into a parsec-web tree: its elements are
Ns::Xmlwith their names as written, its attributes’ namespaces areAttrNs::Hostids, andnamesholds what those ids stand for. The host keeps namespace declarations out of the attributes.
Enums§
- Item
- A node in XPath’s data model: a tree node, or an attribute or
namespace node (which the tree keeps on its element rather than as a
node of its own). Twelve bytes: a node-set can hold every node of a big
page, so its name, namespace and value are read from the tree
(
Tree::attribute,Doc::namespace_at), not kept here. - Node
Type - A node’s kind, numbered as the DOM’s
nodeTypenumbers them. - TagKey
- What
crate::Indexgroups elements by for name tests. Elements with the same name lowercased share a group however the tree names them, so a query’s name is looked up once, not compared on every element. - Value
- What an expression evaluates to. A node-set is in document order, without duplicates.
- XValue
- A value a caller can bind to a
$variable.
Constants§
- CDATA
- COMMENT
- DOCTYPE
- DOCUMENT
- ELEMENT
- The node kinds, as the index stores them: the DOM’s nodeType numbers.
- PI
- TEXT
- WORK_
LIMIT - How much work one run may do before it gives up: nodes looked at on
axes and by
lang(), predicate tests, and nodes and every 16 bytes of text read for string-values. Some queries are quadratic on any engine (//p[following::p]), and a hostile page can make them run for hours. A unit takes one to twenty-odd nanoseconds, so this is a few seconds at most: still over ten times what the slowest query of the benchmark pages needs. - XML_
DECL - The
declof anItem::Nsfor thexmlnamespace, which every element has. - XML_NS
- The namespace the
xmlprefix is always bound to.
Traits§
- Extensions
- Functions beyond XPath 1.0’s core library, which a caller provides. A core function of the same name wins.
- Namespaces
- The namespaces of an XML document built into a parsec-web tree, which the tree leaves to its host. Ids are the host’s; 0 is no namespace.
- Tree
- A tree XPath can query. Every method takes a node id below
Tree::len; a method about elements gives “”, 0 or None for a node of another kind.