% Exemple :
% > xml_interpretor myfile.xml root level1 level2
% > this_is_content_of_level2_tag
I don't understand what you're trying to do here. If the
goal is to specify a node name, or perhaps the path to
the node, and have the contents of the node returned,
what you really want is a program which can execute
XPath queries. Assuming your document looks something
like this
<root>
<level1>
<level2>data</level2>
</level1>
</root>
the XPath query would be
/root/level1/level2
I don't actually know a tool which will do that, but I do know that
you can do it with this XSLT stylesheet
<xsl:stylesheet xmlns:xsl='
http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl
utput method='text'/>
<xsl:template match='/'>
<xsl:value-of select='/root/level1/level2'/>
</xsl:template>
</xsl:stylesheet>
and there are a few command-line xslt processors which can process it.
The problem can be solved by writing a program to generate that stylesheet
based on command-line arguments.
It turns out that xsltproc, the XSLT processor which comes with libxslt,
can read a stylesheet from the command-line, so you can create a shell
script which puts that stylesheet in a HERE document, with the
XPath expression taken from $2. Here's a shell script that does this.
Remove the leading space, stick it in a file in your path
and give it execute permission.
Usage is
findnode docname xpath-expression
#!/bin/sh
if [ $# -ne 2 ]
then
echo "usage $0 doc expression"
exit 1
fi
xsltproc - "$1" <<HERE
<xsl:stylesheet xmlns:xsl='
http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xsl
utput method='text'/>
<xsl:template match='/'>
<xsl:value-of select='$2'/>
</xsl:template>
</xsl:stylesheet>
HERE