473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

extract from xml file

ash
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..
Jul 20 '05 #1
1 2921
In article <67**************************@posting.google.com >,
ash <as**********@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
pt**@interlog.com
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phong Ho | last post by:
Hi everyone, I try to write a simple web crawler. It has to do the following: 1) Open an URL and retrieve a HTML file. 2) Extract news headlines from the HTML file 3) Put the headlines into a...
9
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and...
10
by: Robert Schultz | last post by:
I have a C/C++ file that I simply want to 'extract' a function from. Something like: extract <function name> <c or cpp file> I want it to return from the beginning of the function, to the end. ...
6
by: Mohammad-Reza | last post by:
Hi I want to extract icon of an exe file and want to know how. I look at the MSDN and find out that I can use ExtractIconEx() Windows API but in there are some changes to that api in c# I made...
3
by: Vjay77 | last post by:
I posted this question, but I pressed 'post' and it disappeared. So once again: Problem: I need to go to lets say www.site.com/page.html Imagine that this html code is 6 mb long. I need to...
8
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
1
by: suis | last post by:
Hi Everybody, I have a big dought about, how to read meta data information in a specific file type like .MSG , anyway thanks to this URL bellow . Edanmo has done a great job for that. ...
5
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.