pub struct Node<'a, 'input: 'a> { /* private fields */ }
Expand description
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 The use of document-order in DOM Selectors is described here in the W3C Selectors API Level 1
Implementations§
source§impl<'a, 'input: 'a> Node<'a, 'input>
impl<'a, 'input: 'a> Node<'a, 'input>
sourcepub fn is_element(&self) -> bool
pub fn is_element(&self) -> bool
Checks that node is an element node.
Examples found in repository?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example print_pos -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(doc) => doc,
Err(e) => {
println!("Error: {}.", e);
return;
}
};
// TODO: finish
for node in doc.descendants() {
if node.is_element() {
println!(
"{:?} at {}",
node.tag_name(),
doc.text_pos_at(node.range().start)
);
}
}
}
More examples
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn is_comment(&self) -> bool
pub fn is_comment(&self) -> bool
Checks that node is a comment node.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn tag_name(&self) -> ExpandedName<'a, 'input>
pub fn tag_name(&self) -> ExpandedName<'a, 'input>
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");
Examples found in repository?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example print_pos -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(doc) => doc,
Err(e) => {
println!("Error: {}.", e);
return;
}
};
// TODO: finish
for node in doc.descendants() {
if node.is_element() {
println!(
"{:?} at {}",
node.tag_name(),
doc.text_pos_at(node.range().start)
);
}
}
}
sourcepub fn has_tag_name<'n, 'm, N>(&self, name: N) -> boolwhere
N: Into<ExpandedName<'n, 'm>>,
pub fn has_tag_name<'n, 'm, N>(&self, name: N) -> boolwhere
N: Into<ExpandedName<'n, 'm>>,
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")));
sourcepub fn default_namespace(&self) -> Option<&'a str>
pub fn default_namespace(&self) -> Option<&'a 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);
sourcepub fn lookup_prefix(&self, uri: &str) -> Option<&'input str>
pub fn lookup_prefix(&self, uri: &str) -> Option<&'input 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"));
sourcepub fn lookup_namespace_uri(&self, prefix: Option<&str>) -> Option<&'a str>
pub fn lookup_namespace_uri(&self, prefix: Option<&str>) -> Option<&'a 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"));
sourcepub fn attribute<'n, 'm, N>(&self, name: N) -> Option<&'a str>where
N: Into<ExpandedName<'n, 'm>>,
pub fn attribute<'n, 'm, N>(&self, name: N) -> Option<&'a str>where
N: Into<ExpandedName<'n, 'm>>,
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"));
sourcepub fn attribute_node<'n, 'm, N>(
&self,
name: N
) -> Option<Attribute<'a, 'input>>where
N: Into<ExpandedName<'n, 'm>>,
pub fn attribute_node<'n, 'm, N>(
&self,
name: N
) -> Option<Attribute<'a, 'input>>where
N: Into<ExpandedName<'n, 'm>>,
Returns element’s attribute object.
The same as attribute()
, but returns the Attribute
itself instead of a value string.
sourcepub fn has_attribute<'n, 'm, N>(&self, name: N) -> boolwhere
N: Into<ExpandedName<'n, 'm>>,
pub fn has_attribute<'n, 'm, N>(&self, name: N) -> boolwhere
N: Into<ExpandedName<'n, 'm>>,
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")));
sourcepub fn attributes(&self) -> Attributes<'a, 'input> ⓘ
pub fn attributes(&self) -> Attributes<'a, 'input> ⓘ
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);
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn namespaces(&self) -> NamespaceIter<'a, 'input> ⓘ
pub fn namespaces(&self) -> NamespaceIter<'a, 'input> ⓘ
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);
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn text(&self) -> Option<&'a str>
pub fn text(&self) -> Option<&'a 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 "));
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn text_storage(&self) -> Option<&'a StringStorage<'input>>
pub fn text_storage(&self) -> Option<&'a StringStorage<'input>>
Returns node’s text storage.
Useful when you need a more low-level access to an allocated string.
sourcepub fn tail(&self) -> Option<&'a str>
pub fn tail(&self) -> Option<&'a 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"));
sourcepub fn tail_storage(&self) -> Option<&'a StringStorage<'input>>
pub fn tail_storage(&self) -> Option<&'a StringStorage<'input>>
Returns element’s tail text storage.
Useful when you need a more low-level access to an allocated string.
sourcepub fn parent_element(&self) -> Option<Self>
pub fn parent_element(&self) -> Option<Self>
Returns the parent element of this node.
sourcepub fn prev_sibling(&self) -> Option<Self>
pub fn prev_sibling(&self) -> Option<Self>
Returns the previous sibling of this node.
sourcepub fn prev_sibling_element(&self) -> Option<Self>
pub fn prev_sibling_element(&self) -> Option<Self>
Returns the previous sibling element of this node.
sourcepub fn next_sibling(&self) -> Option<Self>
pub fn next_sibling(&self) -> Option<Self>
Returns the next sibling of this node.
sourcepub fn next_sibling_element(&self) -> Option<Self>
pub fn next_sibling_element(&self) -> Option<Self>
Returns the next sibling element of this node.
sourcepub fn first_child(&self) -> Option<Self>
pub fn first_child(&self) -> Option<Self>
Returns the first child of this node.
sourcepub fn first_element_child(&self) -> Option<Self>
pub fn first_element_child(&self) -> Option<Self>
Returns the first element child of this node.
sourcepub fn last_child(&self) -> Option<Self>
pub fn last_child(&self) -> Option<Self>
Returns the last child of this node.
sourcepub fn last_element_child(&self) -> Option<Self>
pub fn last_element_child(&self) -> Option<Self>
Returns the last element child of this node.
sourcepub fn has_siblings(&self) -> bool
pub fn has_siblings(&self) -> bool
Returns true if this node has siblings.
sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children.
sourcepub fn ancestors(&self) -> AxisIter<'a, 'input> ⓘ
pub fn ancestors(&self) -> AxisIter<'a, 'input> ⓘ
Returns an iterator over ancestor nodes starting at this node.
sourcepub fn prev_siblings(&self) -> AxisIter<'a, 'input> ⓘ
pub fn prev_siblings(&self) -> AxisIter<'a, 'input> ⓘ
Returns an iterator over previous sibling nodes starting at this node.
sourcepub fn next_siblings(&self) -> AxisIter<'a, 'input> ⓘ
pub fn next_siblings(&self) -> AxisIter<'a, 'input> ⓘ
Returns an iterator over next sibling nodes starting at this node.
sourcepub fn first_children(&self) -> AxisIter<'a, 'input> ⓘ
pub fn first_children(&self) -> AxisIter<'a, 'input> ⓘ
Returns an iterator over first children nodes starting at this node.
sourcepub fn last_children(&self) -> AxisIter<'a, 'input> ⓘ
pub fn last_children(&self) -> AxisIter<'a, 'input> ⓘ
Returns an iterator over last children nodes starting at this node.
sourcepub fn descendants(&self) -> Descendants<'a, 'input> ⓘ
pub fn descendants(&self) -> Descendants<'a, 'input> ⓘ
Returns an iterator over this node and its descendants.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example stats -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(v) => v,
Err(e) => {
println!("Error: {}.", e);
std::process::exit(1);
}
};
println!(
"Elements count: {}",
doc.root().descendants().filter(|n| n.is_element()).count()
);
let attrs_count: usize = doc.root().descendants().map(|n| n.attributes().len()).sum();
println!("Attributes count: {}", attrs_count);
let ns_count: usize = doc.root().descendants().map(|n| n.namespaces().len()).sum();
println!("Namespaces count: {}", ns_count);
let mut uris = HashSet::new();
for node in doc.root().descendants() {
for ns in node.namespaces() {
uris.insert((
ns.name().unwrap_or("\"\"").to_string(),
ns.uri().to_string(),
));
}
}
println!("Unique namespaces count: {}", uris.len());
if !uris.is_empty() {
println!("Unique namespaces:");
for (key, value) in uris {
println!(" {:?}: {}", key, value);
}
}
println!(
"Comments count: {}",
doc.root().descendants().filter(|n| n.is_comment()).count()
);
println!("Comments:");
for node in doc.root().descendants().filter(|n| n.is_comment()) {
println!("{:?}", node.text().unwrap());
}
}
sourcepub fn range(&self) -> Range<usize>
pub fn range(&self) -> Range<usize>
Returns node’s range in bytes in the original document.
Examples found in repository?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() {
let args: Vec<_> = std::env::args().collect();
if args.len() != 2 {
println!("Usage:\n\tcargo run --example print_pos -- input.xml");
std::process::exit(1);
}
let text = std::fs::read_to_string(&args[1]).unwrap();
let opt = roxmltree::ParsingOptions {
allow_dtd: true,
..roxmltree::ParsingOptions::default()
};
let doc = match roxmltree::Document::parse_with_options(&text, opt) {
Ok(doc) => doc,
Err(e) => {
println!("Error: {}.", e);
return;
}
};
// TODO: finish
for node in doc.descendants() {
if node.is_element() {
println!(
"{:?} at {}",
node.tag_name(),
doc.text_pos_at(node.range().start)
);
}
}
}
Trait Implementations§
source§impl Ord for Node<'_, '_>
impl Ord for Node<'_, '_>
source§impl PartialEq for Node<'_, '_>
impl PartialEq for Node<'_, '_>
source§impl PartialOrd for Node<'_, '_>
impl PartialOrd for Node<'_, '_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more