extract from xml file

Discussion in 'XML' started by ash, Sep 9, 2003.

  1. ash

    ash Guest

    My input file is something like this

    <DB>
    <E>
    <TAG1><![DATA[ "ep87" ]]></TAG1>
    <TAG2><![DATA[ "0" ]]></TAG2>
    <TAG3><![DATA[ "8.8.8.7" ]]></TAG3>
    </E>
    <E>
    <TAG1><![DATA[ "EP7-1" ]]></TAG1>
    <TAG2><![DATA[ "0" ]]></TAG2>
    <TAG3><![DATA[ "192.168.5.1" ]]></TAG3>
    </E>

    </DB>

    I want to able to search on string ep87 and get the output like

    <E>
    <TAG1><![DATA[ "ep87" ]]></TAG1>
    <TAG2><![DATA[ "0" ]]></TAG2>
    <TAG3><![DATA[ "8.8.8.7" ]]></TAG3>
    </E>

    What tool or script can I use?
    Thank You..
     
    ash, Sep 9, 2003
    #1
    1. Advertising

  2. In article <>,
    ash <> wrote:

    % My input file is something like this
    %
    % <DB>
    % <E>
    % <TAG1><![DATA[ "ep87" ]]></TAG1>

    This should be [CDATA[

    [...]

    % I want to able to search on string ep87 and get the output like
    %
    % <E>
    % <TAG1><![DATA[ "ep87" ]]></TAG1>
    % <TAG2><![DATA[ "0" ]]></TAG2>
    % <TAG3><![DATA[ "8.8.8.7" ]]></TAG3>
    % </E>

    % What tool or script can I use?

    You could do this with xslt:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml"/>

    <xsl:param name="ep87" select="'ep87'"/>

    <xsl:template match="text()"/>

    <xsl:template match="TAG1[contains(., $ep87)]">
    <xsl:copy-of select="parent::*"/>
    </xsl:template>
    </xsl:stylesheet>

    most (all?) xslt tools will let you set a parameter from the command-line.
    For instance, with xsltproc, you can run the above with

    xsltproc --param ep87 "'EP7-1'" query.xsl data.xml

    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Sep 9, 2003
    #2
    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. =?Utf-8?B?QW5keQ==?=

    Showing an extract of XML file in a datagrid

    =?Utf-8?B?QW5keQ==?=, May 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    295
    =?Utf-8?B?QW5keQ==?=
    May 19, 2004
  2. Harry Zoroc
    Replies:
    1
    Views:
    964
    Gregory Vaughan
    Jul 12, 2004
  3. jkflens
    Replies:
    2
    Views:
    1,515
    jkflens
    May 30, 2006
  4. peter pilsl
    Replies:
    1
    Views:
    2,088
    Richard Tobin
    Nov 18, 2007
  5. Erik Wasser
    Replies:
    5
    Views:
    484
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page