pub trait Tree: Sync {
Show 20 methods
// Required methods
fn len(&self) -> usize;
fn kind(&self, n: NodeId) -> NodeType;
fn parent(&self, n: NodeId) -> Option<NodeId>;
fn first_child(&self, n: NodeId) -> Option<NodeId>;
fn next_sibling(&self, n: NodeId) -> Option<NodeId>;
fn prev_sibling(&self, n: NodeId) -> Option<NodeId>;
fn qualified_name(&self, n: NodeId) -> &str;
fn local_name(&self, n: NodeId) -> &str;
fn namespace_uri(&self, n: NodeId) -> &str;
fn tag_key(&self, n: NodeId) -> TagKey<'_>;
fn attribute_count(&self, n: NodeId) -> u32;
fn attribute(&self, n: NodeId, i: u32) -> Option<Attr<'_>>;
fn data(&self, n: NodeId) -> &str;
fn pi_target(&self, n: NodeId) -> Option<&str>;
fn is_xml(&self) -> bool;
fn id(&self, n: NodeId) -> Option<&str>;
fn lang(&self, n: NodeId) -> Option<&str>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn namespace_declaration_count(&self, _n: NodeId) -> u32 { ... }
fn namespace_declaration(&self, _n: NodeId, _i: u32) -> Option<(&str, &str)> { ... }
}Expand description
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.
Required Methods§
fn kind(&self, n: NodeId) -> NodeType
fn parent(&self, n: NodeId) -> Option<NodeId>
fn first_child(&self, n: NodeId) -> Option<NodeId>
fn next_sibling(&self, n: NodeId) -> Option<NodeId>
fn prev_sibling(&self, n: NodeId) -> Option<NodeId>
Sourcefn qualified_name(&self, n: NodeId) -> &str
fn qualified_name(&self, n: NodeId) -> &str
An element’s name as written, with any prefix: what name()
gives. Lowercase in HTML.
Sourcefn local_name(&self, n: NodeId) -> &str
fn local_name(&self, n: NodeId) -> &str
An element’s name without its prefix: what local-name() gives.
Sourcefn namespace_uri(&self, n: NodeId) -> &str
fn namespace_uri(&self, n: NodeId) -> &str
An element’s namespace URI; “” for no namespace.
Sourcefn tag_key(&self, n: NodeId) -> TagKey<'_>
fn tag_key(&self, n: NodeId) -> TagKey<'_>
What crate::Index keys an element’s name tests on.
Sourcefn attribute_count(&self, n: NodeId) -> u32
fn attribute_count(&self, n: NodeId) -> u32
How many attributes an element has. In XPath’s data model,
xmlns and xmlns:* are namespace nodes rather than attributes, so
an XML tree leaves them out of these. An HTML tree keeps them, as
libxml2’s HTML parser does.
Sourcefn attribute(&self, n: NodeId, i: u32) -> Option<Attr<'_>>
fn attribute(&self, n: NodeId, i: u32) -> Option<Attr<'_>>
An element’s ith attribute, in document order. A query reads
attributes by place, so this should take constant time.
Sourcefn data(&self, n: NodeId) -> &str
fn data(&self, n: NodeId) -> &str
A text, CDATA section, comment or processing instruction’s text.
Sourcefn is_xml(&self) -> bool
fn is_xml(&self) -> bool
Whether names compare exactly (XML), rather than ignoring ASCII case with prefixes left as part of the name (HTML).
Provided Methods§
fn is_empty(&self) -> bool
Sourcefn namespace_declaration_count(&self, _n: NodeId) -> u32
fn namespace_declaration_count(&self, _n: NodeId) -> u32
How many namespaces node n declares: an XML element’s xmlns
and xmlns:* attributes. A root that isn’t an element may declare
the namespaces in scope where its tree was cut from, which its
elements then inherit. The namespace axis works out what’s in scope
from these. None by default, as an HTML tree has none: its elements
have only the xml namespace, which is always in scope.
Sourcefn namespace_declaration(&self, _n: NodeId, _i: u32) -> Option<(&str, &str)>
fn namespace_declaration(&self, _n: NodeId, _i: u32) -> Option<(&str, &str)>
Node n’s ith declaration, in the order written: the prefix (“”
for the default namespace) and the URI (“” for xmlns="", which
takes the binding away). Of two for one prefix on a node, the
first counts. This should take constant time.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Tree for Document
An HTML page. Names are the parser’s lowercase ones in no namespace,
and a colon is part of a name (fb:like), as in lxml.
impl Tree for Document
An HTML page. Names are the parser’s lowercase ones in no namespace,
and a colon is part of a name (fb:like), as in lxml.