Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 07:09 AM
ash
Guest
 
Posts: n/a
Default extract from xml file

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..
  #2  
Old July 20th, 2005, 07:09 AM
Patrick TJ McPhee
Guest
 
Posts: n/a
Default Re: extract from xml file

In article <67b028c8.0309090100.1799872f@posting.google.com >,
ash <ashishmathur@msn.com> 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:output 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
ptjm@interlog.com
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles