Struct roxmltree::Node [−][src]
pub struct Node<'a, 'd: 'a> { /* fields omitted */ }
A node.
Methods
impl<'a, 'd: 'a> Node<'a, 'd>
[src]
impl<'a, 'd: 'a> Node<'a, 'd>
pub fn node_type(&self) -> NodeType
[src]
pub fn node_type(&self) -> NodeType
Returns node's type.
pub fn is_root(&self) -> bool
[src]
pub fn is_root(&self) -> bool
Checks that node is a root node.
pub fn is_element(&self) -> bool
[src]
pub fn is_element(&self) -> bool
Checks that node is an element node.
pub fn is_pi(&self) -> bool
[src]
pub fn is_pi(&self) -> bool
Checks that node is a processing instruction node.
pub fn is_comment(&self) -> bool
[src]
pub fn is_comment(&self) -> bool
Checks that node is a comment node.
pub fn is_text(&self) -> bool
[src]
pub fn is_text(&self) -> bool
Checks that node is a text node.
pub fn document(&self) -> &Document
[src]
pub fn document(&self) -> &Document
Returns node's document.
pub fn tag_name(&'a self) -> ExpandedName<'a>
[src]
pub fn tag_name(&'a self) -> ExpandedName<'a>
Returns node's tag name.
Returns an empty name with no namespace if the current node is not an element.
Examples
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().tag_name().namespace(), Some("http://www.w3.org")); assert_eq!(doc.root_element().tag_name().name(), "e");
pub fn has_tag_name<N>(&self, name: N) -> bool where
N: Into<ExpandedName<'a>>,
[src]
pub fn has_tag_name<N>(&self, name: N) -> bool where
N: Into<ExpandedName<'a>>,
Checks that node has a specified tag name.
Examples
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap(); assert!(doc.root_element().has_tag_name("e")); assert!(doc.root_element().has_tag_name(("http://www.w3.org", "e"))); assert!(!doc.root_element().has_tag_name("b")); assert!(!doc.root_element().has_tag_name(("http://www.w4.org", "e")));
pub fn default_namespace(&self) -> Option<&str>
[src]
pub fn default_namespace(&self) -> Option<&str>
Returns node's default namespace URI.
Examples
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().default_namespace(), Some("http://www.w3.org"));
let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().default_namespace(), None);
pub fn resolve_tag_name_prefix(&self) -> Option<&str>
[src]
pub fn resolve_tag_name_prefix(&self) -> Option<&str>
Returns element's namespace prefix.
Returns None
:
- if the current node is not an element
- if the current element has a default namespace
- if the current element has no namespace
Examples
let doc = roxmltree::Document::parse("<n:e xmlns:n='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().resolve_tag_name_prefix(), Some("n"));
let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().resolve_tag_name_prefix(), None);
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().resolve_tag_name_prefix(), None);
pub fn lookup_prefix(&self, uri: &str) -> Option<&str>
[src]
pub fn lookup_prefix(&self, uri: &str) -> Option<&str>
Returns a prefix for a given namespace URI.
Examples
let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().lookup_prefix("http://www.w3.org"), Some("n"));
let doc = roxmltree::Document::parse("<e xmlns:n=''/>").unwrap(); assert_eq!(doc.root_element().lookup_prefix(""), Some("n"));
pub fn lookup_namespace_uri(&self, prefix: Option<&'a str>) -> Option<&str>
[src]
pub fn lookup_namespace_uri(&self, prefix: Option<&'a str>) -> Option<&str>
Returns an URI for a given prefix.
Examples
let doc = roxmltree::Document::parse("<e xmlns:n='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().lookup_namespace_uri(Some("n")), Some("http://www.w3.org"));
let doc = roxmltree::Document::parse("<e xmlns='http://www.w3.org'/>").unwrap(); assert_eq!(doc.root_element().lookup_namespace_uri(None), Some("http://www.w3.org"));
pub fn attribute<N>(&self, name: N) -> Option<&str> where
N: Into<ExpandedName<'a>>,
[src]
pub fn attribute<N>(&self, name: N) -> Option<&str> where
N: Into<ExpandedName<'a>>,
Returns element's attribute value.
Examples
let doc = roxmltree::Document::parse("<e a='b'/>").unwrap(); assert_eq!(doc.root_element().attribute("a"), Some("b"));
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>" ).unwrap(); assert_eq!(doc.root_element().attribute("a"), Some("b")); assert_eq!(doc.root_element().attribute(("http://www.w3.org", "a")), Some("c"));
pub fn has_attribute<N>(&self, name: N) -> bool where
N: Into<ExpandedName<'a>>,
[src]
pub fn has_attribute<N>(&self, name: N) -> bool where
N: Into<ExpandedName<'a>>,
Checks that element has a specified attribute.
Examples
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>" ).unwrap(); assert!(doc.root_element().has_attribute("a")); assert!(doc.root_element().has_attribute(("http://www.w3.org", "a"))); assert!(!doc.root_element().has_attribute("b")); assert!(!doc.root_element().has_attribute(("http://www.w4.org", "a")));
pub fn attributes(&self) -> &[Attribute]
[src]
pub fn attributes(&self) -> &[Attribute]
Returns element's attributes.
Examples
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>" ).unwrap(); assert_eq!(doc.root_element().attributes().len(), 2);
pub fn attribute_pos<N>(&self, name: N) -> Option<TextPos> where
N: Into<ExpandedName<'a>>,
[src]
pub fn attribute_pos<N>(&self, name: N) -> Option<TextPos> where
N: Into<ExpandedName<'a>>,
Calculates attribute's position in the original document.
Note: this operation is expensive.
Examples
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>" ).unwrap(); assert_eq!(doc.root_element().attribute_pos("a"), Some(roxmltree::TextPos::new(1, 32))); assert_eq!(doc.root_element().attribute_pos(("http://www.w3.org", "a")), Some(roxmltree::TextPos::new(1, 38)));
pub fn attribute_value_pos<N>(&self, name: N) -> Option<TextPos> where
N: Into<ExpandedName<'a>>,
[src]
pub fn attribute_value_pos<N>(&self, name: N) -> Option<TextPos> where
N: Into<ExpandedName<'a>>,
Calculates attribute's value position in the original document.
Note: this operation is expensive.
Examples
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org' a='b' n:a='c'/>" ).unwrap(); assert_eq!(doc.root_element().attribute_value_pos("a"), Some(roxmltree::TextPos::new(1, 35))); assert_eq!(doc.root_element().attribute_value_pos(("http://www.w3.org", "a")), Some(roxmltree::TextPos::new(1, 43)));
pub fn namespaces(&self) -> &[Namespace]
[src]
pub fn namespaces(&self) -> &[Namespace]
Returns element's namespaces.
Examples
let doc = roxmltree::Document::parse( "<e xmlns:n='http://www.w3.org'/>" ).unwrap(); assert_eq!(doc.root_element().namespaces().len(), 1);
pub fn text(&self) -> Option<&str>
[src]
pub fn text(&self) -> Option<&str>
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
Examples
let doc = roxmltree::Document::parse("\ <p> text </p> ").unwrap(); assert_eq!(doc.root_element().text(), Some("\n text\n")); assert_eq!(doc.root_element().first_child().unwrap().text(), Some("\n text\n"));
let doc = roxmltree::Document::parse("<!-- comment --><e/>").unwrap(); assert_eq!(doc.root().first_child().unwrap().text(), Some(" comment "));
pub fn tail(&self) -> Option<&str>
[src]
pub fn tail(&self) -> Option<&str>
Returns element's tail text.
Examples
let doc = roxmltree::Document::parse("\ <root> text1 <p/> text2 </root> ").unwrap(); let p = doc.descendants().find(|n| n.has_tag_name("p")).unwrap(); assert_eq!(p.tail(), Some("\n text2\n"));
pub fn pi(&self) -> Option<PI>
[src]
pub fn pi(&self) -> Option<PI>
Returns node as Processing Instruction.
pub fn parent(&self) -> Option<Self>
[src]
pub fn parent(&self) -> Option<Self>
Returns the parent of this node.
pub fn parent_element(&self) -> Option<Self>
[src]
pub fn parent_element(&self) -> Option<Self>
Returns the parent element of this node.
pub fn prev_sibling(&self) -> Option<Self>
[src]
pub fn prev_sibling(&self) -> Option<Self>
Returns the previous sibling of this node.
pub fn next_sibling(&self) -> Option<Self>
[src]
pub fn next_sibling(&self) -> Option<Self>
Returns the next sibling of this node.
pub fn first_child(&self) -> Option<Self>
[src]
pub fn first_child(&self) -> Option<Self>
Returns the first child of this node.
pub fn first_element_child(&self) -> Option<Self>
[src]
pub fn first_element_child(&self) -> Option<Self>
Returns the first element child of this node.
pub fn last_child(&self) -> Option<Self>
[src]
pub fn last_child(&self) -> Option<Self>
Returns the last child of this node.
pub fn last_element_child(&self) -> Option<Self>
[src]
pub fn last_element_child(&self) -> Option<Self>
Returns the last element child of this node.
pub fn has_siblings(&self) -> bool
[src]
pub fn has_siblings(&self) -> bool
Returns true if this node has siblings.
pub fn has_children(&self) -> bool
[src]
pub fn has_children(&self) -> bool
Returns true if this node has children.
ⓘImportant traits for Ancestors<'a, 'd>pub fn ancestors(&self) -> Ancestors<'a, 'd>
[src]
pub fn ancestors(&self) -> Ancestors<'a, 'd>
Returns an iterator over ancestor nodes.
ⓘImportant traits for PrevSiblings<'a, 'd>pub fn prev_siblings(&self) -> PrevSiblings<'a, 'd>
[src]
pub fn prev_siblings(&self) -> PrevSiblings<'a, 'd>
Returns an iterator over previous sibling nodes.
ⓘImportant traits for NextSiblings<'a, 'd>pub fn next_siblings(&self) -> NextSiblings<'a, 'd>
[src]
pub fn next_siblings(&self) -> NextSiblings<'a, 'd>
Returns an iterator over next sibling nodes.
ⓘImportant traits for FirstChildren<'a, 'd>pub fn first_children(&self) -> FirstChildren<'a, 'd>
[src]
pub fn first_children(&self) -> FirstChildren<'a, 'd>
Returns an iterator over first children nodes.
ⓘImportant traits for LastChildren<'a, 'd>pub fn last_children(&self) -> LastChildren<'a, 'd>
[src]
pub fn last_children(&self) -> LastChildren<'a, 'd>
Returns an iterator over last children nodes.
ⓘImportant traits for Children<'a, 'd>pub fn children(&self) -> Children<'a, 'd>
[src]
pub fn children(&self) -> Children<'a, 'd>
Returns an iterator over children nodes.
ⓘImportant traits for Traverse<'a, 'd>pub fn traverse(&self) -> Traverse<'a, 'd>
[src]
pub fn traverse(&self) -> Traverse<'a, 'd>
Returns an iterator which traverses the subtree starting at this node.
ⓘImportant traits for Descendants<'a, 'd>pub fn descendants(&self) -> Descendants<'a, 'd>
[src]
pub fn descendants(&self) -> Descendants<'a, 'd>
Returns an iterator over this node and its descendants.
pub fn pos(&self) -> usize
[src]
pub fn pos(&self) -> usize
Returns node's position in bytes in the original document.
pub fn node_pos(&self) -> TextPos
[src]
pub fn node_pos(&self) -> TextPos
Calculates node's position in the original document.
Note: this operation is expensive.
Examples
let doc = roxmltree::Document::parse("\ <!-- comment --> <e/>" ).unwrap(); assert_eq!(doc.root_element().node_pos(), roxmltree::TextPos::new(2, 1));
Trait Implementations
impl<'a, 'd> Copy for Node<'a, 'd>
[src]
impl<'a, 'd> Copy for Node<'a, 'd>
impl<'a, 'd> Clone for Node<'a, 'd>
[src]
impl<'a, 'd> Clone for Node<'a, 'd>
fn clone(&self) -> Self
[src]
fn clone(&self) -> Self
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'a, 'd> Eq for Node<'a, 'd>
[src]
impl<'a, 'd> Eq for Node<'a, 'd>
impl<'a, 'd> PartialEq for Node<'a, 'd>
[src]
impl<'a, 'd> PartialEq for Node<'a, 'd>
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl<'a, 'd: 'a> Debug for Node<'a, 'd>
[src]
impl<'a, 'd: 'a> Debug for Node<'a, 'd>