xml interpretor in batch mode

Discussion in 'XML' started by M, Oct 24, 2003.

  1. M

    M Guest

    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
     
    M, Oct 24, 2003
    #1
    1. Advertising

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

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Oct 24, 2003
    #2
    1. Advertising

  3. In article <bnbpub$p8l$>,
    Patrick TJ McPhee <> 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
     
    Patrick TJ McPhee, Oct 25, 2003
    #3
  4. 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/
     
    Mikhail Grouchinsky, Oct 27, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Balaji

    Interpretor.

    Balaji, Oct 26, 2004, in forum: Python
    Replies:
    3
    Views:
    407
    Mark 'Kamikaze' Hughes
    Oct 27, 2004
  2. John J Lee
    Replies:
    3
    Views:
    520
    bruno at modulix
    Dec 1, 2005
  3. sunil
    Replies:
    1
    Views:
    405
    Fei Liu
    Jun 12, 2008
  4. Yogesh Sharma
    Replies:
    4
    Views:
    312
    Yogesh Sharma
    Apr 3, 2005
  5. Micla

    No-install Perl Interpretor

    Micla, Jun 7, 2004, in forum: Perl Misc
    Replies:
    15
    Views:
    239
    Michele Dondi
    Jun 9, 2004
Loading...

Share This Page