1#[cfg(feature = "positions")]
2fn main() {
3 let args: Vec<_> = std::env::args().collect();
4
5 if args.len() != 2 {
6 println!("Usage:\n\tcargo run --example print_pos -- input.xml");
7 std::process::exit(1);
8 }
9
10 let text = std::fs::read_to_string(&args[1]).unwrap();
11 let opt = roxmltree::ParsingOptions {
12 allow_dtd: true,
13 ..roxmltree::ParsingOptions::default()
14 };
15 let doc = match roxmltree::Document::parse_with_options(&text, opt) {
16 Ok(doc) => doc,
17 Err(e) => {
18 println!("Error: {}.", e);
19 return;
20 }
21 };
22
23 for node in doc.descendants() {
25 if node.is_element() {
26 println!(
27 "{:?} at {}",
28 node.tag_name(),
29 doc.text_pos_at(node.range().start)
30 );
31 }
32 }
33}
34
35#[cfg(not(feature = "positions"))]
36fn main() {}