Skip to main content

Tree

Trait Tree 

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

Source

fn len(&self) -> usize

How many node ids there are, including those of removed nodes.

Source

fn kind(&self, n: NodeId) -> NodeType

Source

fn parent(&self, n: NodeId) -> Option<NodeId>

Source

fn first_child(&self, n: NodeId) -> Option<NodeId>

Source

fn next_sibling(&self, n: NodeId) -> Option<NodeId>

Source

fn prev_sibling(&self, n: NodeId) -> Option<NodeId>

Source

fn qualified_name(&self, n: NodeId) -> &str

An element’s name as written, with any prefix: what name() gives. Lowercase in HTML.

Source

fn local_name(&self, n: NodeId) -> &str

An element’s name without its prefix: what local-name() gives.

Source

fn namespace_uri(&self, n: NodeId) -> &str

An element’s namespace URI; “” for no namespace.

Source

fn tag_key(&self, n: NodeId) -> TagKey<'_>

What crate::Index keys an element’s name tests on.

Source

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.

Source

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.

Source

fn data(&self, n: NodeId) -> &str

A text, CDATA section, comment or processing instruction’s text.

Source

fn pi_target(&self, n: NodeId) -> Option<&str>

A processing instruction’s target.

Source

fn is_xml(&self) -> bool

Whether names compare exactly (XML), rather than ignoring ASCII case with prefixes left as part of the name (HTML).

Source

fn id(&self, n: NodeId) -> Option<&str>

The value id() finds an element by: HTML’s id, or XML’s xml:id or an attribute the DTD declares an ID.

Source

fn lang(&self, n: NodeId) -> Option<&str>

The language an element declares, if it declares one, for lang(): xml:lang, or HTML’s lang.

Provided Methods§

Source

fn is_empty(&self) -> bool

Source

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.

Source

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.

Source§

fn len(&self) -> usize

Source§

fn kind(&self, n: NodeId) -> NodeType

Source§

fn parent(&self, n: NodeId) -> Option<NodeId>

Source§

fn first_child(&self, n: NodeId) -> Option<NodeId>

Source§

fn next_sibling(&self, n: NodeId) -> Option<NodeId>

Source§

fn prev_sibling(&self, n: NodeId) -> Option<NodeId>

Source§

fn qualified_name(&self, n: NodeId) -> &str

Source§

fn local_name(&self, n: NodeId) -> &str

Source§

fn namespace_uri(&self, _: NodeId) -> &str

Source§

fn tag_key(&self, n: NodeId) -> TagKey<'_>

Source§

fn attribute_count(&self, n: NodeId) -> u32

Source§

fn attribute(&self, n: NodeId, i: u32) -> Option<Attr<'_>>

Source§

fn data(&self, n: NodeId) -> &str

Source§

fn pi_target(&self, n: NodeId) -> Option<&str>

Source§

fn is_xml(&self) -> bool

Source§

fn id(&self, n: NodeId) -> Option<&str>

Source§

fn lang(&self, n: NodeId) -> Option<&str>

Implementors§

Source§

impl Tree for XmlTree<'_>