Is there a native tool for parsing xml files available on RedHat?

If, given this XML

$ cat a.xml
<a>
  <b>Hello</b>
  <b>World</b>
</a>

You want to be able to do

$ ./xpath //a/b a.xml
Hello
World

then you could just cut & paste this:

$ cat xpath
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;

my $parser = XML::LibXML->new();
my $document = $parser->parse_file($ARGV[1]);
my @nodes = $document->findnodes($ARGV[0]);
for my $node (@nodes) {
  print $node->textContent, "\n";
}

You should be able to install the XML::LibXML module using perl -MCPAN -e 'install XML::LibXML'


Try xmllint and the --xpath option:

<xml>
  <hello>world!</hello>
</xml>

$ xmllint --xpath '//hello/text()'
world!

xsltproc (command line interface to libxslt) is always available on RHEL.
usage: xsltproc xsl_stylesheet xml_file.