in reply to Re: XPath with node names and attributes...
in thread XPath with node names and attributes...
<root> <head> <node1 attr1="Node1 Attribute"> Node1 Value </node1> </head> </root>
use XML::LibXML; $inp = $ARGV[0]; # create object my $parser = XML::LibXML->new(); # read input XML file my $inp_tree = $parser->parse_file($inp); my $inp_root = $inp_tree->getDocumentElement; my $root_text = $inp_root->toString(); $rule_source = "head/node1@attr1"; my @inp_search_nodes = $inp_root->findnodes($rule_source); my $inp_search_results = scalar @inp_search_nodes; if ( 0 == $inp_search_results ) { print "XPath $rule_source not found! \n"; } else { my $path_text = $inp_search_nodes[ 0 ]->findvalue("."); print "Xpath ->: $path_text\n"; my $val = $inp_search_nodes[ 0 ]->textContent(); + print "Value of XPath $rule_source : $val \n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: XPath with node names and attributes...
by thunders (Priest) on Oct 20, 2009 at 17:04 UTC |