Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xml interpretor in batch mode

Reply
Thread Tools

xml interpretor in batch mode

 
 
M
Guest
Posts: n/a
 
      10-24-2003
Hello,

I'm looking for a batch mode software which can return the content of
an XML tag, if it gets the different level tags (root, level1, level2).
For Unix/Linux.

Exemple :
> xml_interpretor myfile.xml root level1 level2
> this_is_content_of_level2_tag


Thanx a lot !
M


 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      10-24-2003
In article <Usenet.cdhojbrr@localhost>, <M> wrote:

% 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 xmlnssl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xslutput 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 xmlnssl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
<xslutput method='text'/>
<xsl:template match='/'>
<xsl:value-of select='$2'/>
</xsl:template>
</xsl:stylesheet>
HERE
--

Patrick TJ McPhee
East York Canada
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      10-25-2003
In article <bnbpub$p8l$(E-Mail Removed)>,
Patrick TJ McPhee <(E-Mail Removed)> wrote:

[if you'll pardon some next-day editing]

% 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

That should be `from the standard input'

--

Patrick TJ McPhee
East York Canada
(E-Mail Removed)
 
Reply With Quote
 
Mikhail Grouchinsky
Guest
Posts: n/a
 
      10-27-2003
M wrote in message news:<Usenet.cdhojbrr@localhost>...
> Hello,
>
> I'm looking for a batch mode software which can return the content of
> an XML tag, if it gets the different level tags (root, level1, level2).
> For Unix/Linux.
>
> Exemple :
> > xml_interpretor myfile.xml root level1 level2
> > this_is_content_of_level2_tag

>
> Thanx a lot !
> M


XmlStarlet http://xmlstar.sourceforge.net/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reg parser for interpretor pattern in C++ sunil C++ 1 06-12-2008 03:11 PM
Embedding Ruby Interpretor in threaded C / C++ Yogesh Sharma Ruby 4 04-03-2005 02:33 PM
Interpretor. Balaji Python 3 10-27-2004 03:25 PM
Safe Mode (?) - It is meant to be normal mode but looks like safe mode English Patient Computer Support 3 10-03-2004 11:10 PM
No-install Perl Interpretor Micla Perl Misc 15 06-09-2004 07:56 PM



Advertisments