raginghomo
New Member
Is there a package out there, for Ubuntu and/or CentOS, that has a command-line tool that can execute an XPath one-liner like \[code\]foo //element@attribute filename.xml\[/code\] or \[code\]foo //element@attribute < filename.xml\[/code\] and return the results line by line?I'm looking for something that would allow me to just \[code\]apt-get install foo\[/code\] or \[code\]yum install foo\[/code\] and then just works out-of-the-box, no wrappers or other adaptation necessary.Here are some examples of things that come close:Nokogiri. If I write this wrapper I could call the wrapper in the way described above:\[code\]#!/usr/bin/rubyrequire 'nokogiri'Nokogiri::XML(STDIN).xpath(ARGV[0]).each do |row| puts rowend\[/code\]XML::XPath. Would work with this wrapper:\[code\]#!/usr/bin/perluse strict;use warnings;use XML::XPath;my $root = XML::XPath->new(ioref => 'STDIN');for my $node ($root->find($ARGV[0])->get_nodelist) { print($node->getData, "\n");}\[/code\]\[code\]xpath\[/code\] from XML::XPath returns too much noise, \[code\]-- NODE --\[/code\] and \[code\]attribute = "value"\[/code\].\[code\]xml_grep\[/code\] from XML::Twig cannot handle expressions that do not return elements, so cannot be used to extract attribute values without further processing.EDIT:\[code\]echo cat //element/@attribute | xmllint --shell filename.xml\[/code\] returns noise similar to \[code\]xpath\[/code\].\[code\]xmllint --xpath //element/@attribute filename.xml\[/code\] returns \[code\]attribute = "value"\[/code\].\[code\]xmllint --xpath 'string(//element/@attribute)' filename.xml\[/code\] returns what I want, but only for the first match.