use fastxml::Parser;
use fastxml::compat::{
create_context, evaluate, find_readonly_nodes_by_xpath, get_node_tag, get_root_node,
get_root_readonly_node, node_to_xml_string,
};
fn main() -> fastxml::error::Result<()> {
let doc = Parser::from(r#"<root><item id="1">a</item><item id="2">b</item></root>"#).parse()?;
println!("=== libxml-compatible API (fastxml::compat) ===\n");
let mut root = get_root_node(&doc)?;
println!("root tag: {}", get_node_tag(&root));
let items = evaluate(&doc, "//item")?;
println!("items found: {}", items.into_nodes().len());
let ctx = create_context(&doc)?;
let ro_root = get_root_readonly_node(&doc)?;
let found = find_readonly_nodes_by_xpath(&ctx, "//item", &ro_root)?;
println!("via context: {} items", found.len());
println!("serialized root:\n{}", node_to_xml_string(&doc, &mut root)?);
Ok(())
}