07-25-2012
Reading block by block in XML
Hi ,
Can you pleas help me with below requirement?
There is only one big line in the file. I need to parse block by block(particular tag values, 'Val' in below case) to get different parameters.
Example:-
Portion of the Input string:-
<?xml version="1.1" encoding="UTF-8"?> <Data><Val Ti="1342750845538" Du="0" De="blackberry8520_ver1RIM" Db="encyclopedia" Pdb="" Uq="0" Dq="0" qry="sdsds?q=dsds" ab="dsds" Dc="4" Te=" Ca="xxx" Sc="320.240" Us="" Cd="X"</Val><Val Ti="1342750845538" Du="0" De="blackberry8520_ver1RIM" Db="home" Pdb="" Uq="0" Dq="0" qry="sdsds?q=dsds&dsdsds=dsds&ss?" ab="dsds" Dc="4" Te=" Ca="xxx" Sc="320.240" Us="" Cd="X"</Val> ..../>
Output:-
If value of Db parameter in <Val> block/tag is not null then I need to show both Db and corresponding qry parameter value.
This should be output for above one :-
encyclopedia -> sdsds?q=dsds
home -> sdsds?q=dsds&dsdsds=dsds&ss
....
....
Thanks in advance.
KM
10 More Discussions You Might Find Interesting
1. Programming
Hello,
I want to know what call to use to read the details of a process control block in solaris ?:) (2 Replies)
Discussion started by: hmurali
2 Replies
2. Shell Programming and Scripting
Hi
I am new to this forum.
I have few XML files and from each xml file I want to copy some specific 50 no of lines and copy them to some other file.
how to do that? pls help.. (5 Replies)
Discussion started by: pritam1980
5 Replies
3. Shell Programming and Scripting
Hi,
There's an xml file produced from a front-end tool as shown below:
<INPUT DATABASE ="ORACLE" DBNAME ="UNIX" NAME ="FACT_TABLE" OWNERNAME ="DIPS">
<INPUTFIELD DATATYPE ="double" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="STORE_KEY" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="15" SCALE... (6 Replies)
Discussion started by: dips_ag
6 Replies
4. Shell Programming and Scripting
hi,
i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment.
so eg..
first block
<filter>
<filter-name>MyRegEx</filter-name>
... (11 Replies)
Discussion started by: Poki
11 Replies
5. Shell Programming and Scripting
I tried searching the forums, but couldn't find anything relevant to my question.
I have an xml file like the following:
<topLevel numberBlock="BLOCK1">
<item="content1" title="Content 1">
<RefPath="path/to/file1.txt />
</item>
<item"content2" title="Content 2" >... (4 Replies)
Discussion started by: jl487
4 Replies
6. Shell Programming and Scripting
Hi All,
I need to umcomment an XML block (if it's not already uncommented) in a shell script. There are several commented blocks in the file that need to remain commented out. The challenging part for me is that I need to match a comment on one line and an XML tag on the following line. Also,... (0 Replies)
Discussion started by: raiderfan1
0 Replies
7. Shell Programming and Scripting
I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed.
See below for the example data.
................................server 1...............................
running process 1
running... (8 Replies)
Discussion started by: Kesavan
8 Replies
8. Shell Programming and Scripting
I want to comment a block of code in xml. Note that the tags will be similar. In the below xml code, I want to block the listener block for com.pkg1.class2. How do i do it ?
Thanks in Advance
<listener>
<listener-class>com.pkg1.class1</listener-class>
</listener>
.........
<listener>... (4 Replies)
Discussion started by: Lakshmikumari
4 Replies
9. Shell Programming and Scripting
I want to extract XML block surrounding search string
Ex: print XML block for string "myapp1-ear" surrounded by "<application> .. </application>"
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<deployment-request>
<requestor>
<first-name>kchinnam</first-name>
... (16 Replies)
Discussion started by: kchinnam
16 Replies
10. UNIX for Beginners Questions & Answers
Hi everyone,
So i'm struggling with an xml (log file) where we get information about some devices, so the logfile is filled with multiple "blocks" like that.
Based on the <devId> i want to extract this part of the xml file. If possible I want it to have an script for this, cause we'll use... (5 Replies)
Discussion started by: Pouky
5 Replies
LEARN ABOUT DEBIAN
template::plugin::xml::xpath
Template::Plugin::XML::XPath(3pm) User Contributed Perl Documentation Template::Plugin::XML::XPath(3pm)
NAME
Template::Plugin::XML::XPath - Plugin interface to XML::XPath
SYNOPSIS
# load plugin and specify XML file to parse
[% USE xpath = XML.XPath(xmlfile) %]
[% USE xpath = XML.XPath(file => xmlfile) %]
[% USE xpath = XML.XPath(filename => xmlfile) %]
# load plugin and specify XML text to parse
[% USE xpath = XML.XPath(xmltext) %]
[% USE xpath = XML.XPath(xml => xmltext) %]
[% USE xpath = XML.XPath(text => xmltext) %]
# then call any XPath methods (see XML::XPath docs)
[% FOREACH page = xpath.findnodes('/html/body/page') %]
[% page.getAttribute('title') %]
[% END %]
# define VIEW to present node(s)
[% VIEW repview notfound='xmlstring' %]
# handler block for a <report>...</report> element
[% BLOCK report %]
[% item.content(view) %]
[% END %]
# handler block for a <section title="...">...</section> element
[% BLOCK section %]
<h1>[% item.getAttribute('title') | html %]</h1>
[% item.content(view) %]
[% END %]
# default template block passes tags through and renders
# out the children recursivly
[% BLOCK xmlstring;
item.starttag; item.content(view); item.endtag;
END %]
# block to generate simple text
[% BLOCK text; item | html; END %]
[% END %]
# now present node (and children) via view
[% repview.print(page) %]
# or print node content via view
[% page.content(repview) %]
DESCRIPTION
This is a Template Toolkit plugin interfacing to the XML::XPath module.
All methods implemented by the XML::XPath modules are available. In addition, the XML::XPath::Node::Element module implements
present($view) and content($view) methods method for seamless integration with Template Toolkit VIEWs. The XML::XPath::Node::Text module
is also adorned with a present($view) method which presents itself via the view using the 'text' template.
To aid the reconstruction of XML, methods starttag and endtag are added to XML::XPath::Node::Element which return the start and end tag for
that element. This means that you can easily do:
[% item.starttag %][% item.content(view) %][% item.endtag %]
To render out the start tag, followed by the content rendered in the view "view", followed by the end tag.
AUTHORS
This plugin module was written by Andy Wardley.
The XML::XPath module is by Matt Sergeant.
COPYRIGHT
Copyright (C) 1996-2006 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Template::Plugin, XML::XPath, XML::Parser
perl v5.8.8 2008-03-01 Template::Plugin::XML::XPath(3pm)