Module amxml::xpath[][src]

(Inner Module) XPath Processor. Caller does not need to know about this module.

Retrieve or apply function to the nodes on XML DOM tree that match the specified xpath.

NodePtr methods each_node(), get_first_node(), get_nodeset() accept xpath as argument. cf. Module amxml::dom -> Struct NodePtr -> Methods.

Examples

use amxml::dom::*;
let xml = r#"<root><a img="a1"/><a img="a2"/></root>"#;
let doc = new_document(xml).unwrap();
let mut img = String::new();
doc.each_node("/root/a", |n| {
    img += n.attribute_value("img").unwrap().as_str();
});
assert_eq!("a1a2", img);

Method each_node() accepts the xpath "/root/a" and pass the matching DOM node 'n' to the closure.

Features that are not implemented yet

  • 'namespace' axis
  • builtin function 'id'
  • variable reference ($var)