Sponsored Content
Top Forums Shell Programming and Scripting Using shell command need to parse multiple nested tag value of a XML file Post 302882798 by NeedASolution on Thursday 9th of January 2014 07:17:44 AM
Old 01-09-2014
Linux Using shell command need to parse multiple nested tag value of a XML file

I have this XML file -

Code:
<gp>
    <mms>1110012</mms>
    <tg>988</tg>
    <mm>LongTime</mm>
    <lv>
        <lkid>StartEle=ONE, Desti = Motion</lkid>
        <kk>12</kk>
    </lv>
    <lv>
        <lkid>StartEle=ONE, Source = Velocity</lkid>
        <kk>2</kk>
    </lv>
    <lv>
        <lkid>StartEle=ONE, Source = Park</lkid>
        <kk>2</kk>
    </lv>
<gp>

<gp>
    <mms>2221100</mms>
    <tg>989</tg>
    <mm>LongVelocity</mm>
    <lv>
        <lkid>StartEle=ONE, Source = Velocity</lkid>
        <kk>772</kk>
    </lv>
    <lv>
        <lkid>StartEle=ONE, Desti = Motion</lkid>
        <kk>900</kk>
    </lv>
    <lv>
        <lkid>StartEle=ONE, Source = Park</lkid>
        <kk>2</kk>
    </lv>
<gp>

Now, I need to first search for "<mm>LongTime</mm>", if found then I have to find for "Desti = Motion" value (which is inside <lkid>StartEle=ONE, Desti = Motion</lkid>) inside the multiple nested sub-tags ... and if that is also found then I finally have to get the value inside the TAG below, which is 12 (<kk>12</kk>).
Please help, using anything - AWK, SED, Grep, anything will do.
Thanks in advance.

Last edited by bartus11; 01-09-2014 at 08:39 AM.. Reason: Please use code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

big xml file with nested loop parse

I have an xml file with the structure: <tag1> <value1>xyx</value1> <value2>123</value2> </tag1> <tag1> <value1>568</value1> <value2>zzzzz</value2> </tag1> where I want to parse each data pair in the this single file, so something like: find first tag1 data pair... (1 Reply)
Discussion started by: unclecameron
1 Replies

2. Shell Programming and Scripting

shell command to remove some XML tag is needed

Hi all, I have a file which i have to remove some line from it, the lines that i have to remove from my file is as below: </new_name></w"s" langue="Fr-fr" version="1.0" encoding="UTF-8" ?> <New_name> and it is finding at the middle of my file, is there any command line in linux to do it or do... (10 Replies)
Discussion started by: id_2pc
10 Replies

3. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

4. Shell Programming and Scripting

awk Script to parse a XML tag

I have an XML tag like this: <property name="agent" value="/var/tmp/root/eclipse" /> Is there way using awk that i can get the value from the above tag. So the output should be: /var/tmp/root/eclipse Help will be appreciated. Regards, Adi (6 Replies)
Discussion started by: asirohi
6 Replies

5. Emergency UNIX and Linux Support

Trying to parse a xml file for only one tag

I have a xml file in where I need to parse only a particular tag and print the output in the shell script. Here is the tag info in the xml file <dp:file> This is dp file output </dp:file> Output should be printed as This is dp file output. Please help.Thank you. (5 Replies)
Discussion started by: chandu123
5 Replies

6. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 Replies

7. Shell Programming and Scripting

Creating multiple xml tag lines in a file

Hi All, Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file. basically I have this xml line <typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/> and say I... (4 Replies)
Discussion started by: Optimus81
4 Replies

8. Shell Programming and Scripting

XML files with spaces in the tag name, parse & display?

Greetings all, I have an XML file that is being generated from my application, here is a sample of the first tag (That I am trying to remove and display in a list..) Example- <tag one= "data" data="1234" updateTime="1300"> <tag one= "data1" data="1234" updateTime="1300"> <tag... (5 Replies)
Discussion started by: jeffs42885
5 Replies

9. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

10. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies
Template::Alloy::Velocity(3pm)				User Contributed Perl Documentation			    Template::Alloy::Velocity(3pm)

NAME
Template::Alloy::Velocity - Velocity (VTL) role DESCRIPTION
The Template::Alloy::Velocity role provides the syntax and the interface for the Velocity Templating Language (VTL). It also brings many of the features from the various templating systems. See the Template::Alloy documentation for configuration and other parameters. The following documents have more information about the velocity language. http://velocity.apache.org/engine/devel/vtl-reference-guide.html http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html?page=4 TODO
Add language usage and samples. ROLE METHODS
"parse_tree_velocity" Used bh the parse_tree method when SYNTAX is set to 'velocity'. "merge" Similar to process_simple, but with syntax set to velocity. UNSUPPORTED VELOCITY SPEC
o The magic Java Velocity property lookups don't exist. You must use the actual method name, Alloy will not try to guess it for you. Java Velocity allows you to type $object.Attribute and Java Velocity will look for the Attribute, getAttribute, getattribute, isAttribute methods. In Perl Alloy, you can call $object.can('Attribute') to introspect the object. o Escaping of variables is consistent. The Java Velocity spec is not. The velocity spec says that "\$email" will return "\$email" if email is not defined and it will return "foo" if email is equal to "foo". The slash behavior magically changes according to the spec. In Alloy the "\$email" would be "$email" if email is not defined. o You can set items to null (undefined) in Alloy. According to the Java Velocity reference-guide you have to configure Velocity to do this. To get the other behavior, you would need to do "#if($questionable)#set($foo=$questionable)#end". The default Velocity spec way provides no way for checking null return values. o There currently isn't a "literal" directive. The VTL reference-guide doesn't mention #literal, but the user-guide does. In Alloy you can use the following: #get('#foreach($a in [1..3]) $a #end') We will probably add the literal support - but it will still have to parse the document, so unless you are using compile_perl, you will parse literal sections multiple times. o There is no "$velocityCount" . Use "$loop.count" . o In Alloy, excess whitespace outside of the directive matters. In the VTL user-guide it mentions that all excess whitespace is gobbled up. Alloy supports the TT chomp operators. These operators are placed just inside the open and close parenthesis of directives as in the following: #set(~ $a = 1 ~) o In Alloy, division using "/" is always floating point. If you want integer division, use "div". In Java Velocity, "/" division is integer only if both numbers are integers. o Perl doesn't support negative ranges. However, arrays do have the reverse method. #foreach( $bar in [-2 .. 2].reverse ) $bar #end o In Alloy arguments to macros are passed by value, not by name. This is easy to achieve with alloy - simply encase your arguments in single quotes and then eval the argument inside the macro. The velocity people claim this feature as a jealously guarded feature. My first template system "WrapEx" had the same feature. It happened as an accident. It represents lazy software architecture and is difficult to optimize. AUTHOR
Paul Seamons <paul at seamons dot com> LICENSE
This module may be distributed under the same terms as Perl itself. perl v5.10.1 2008-09-16 Template::Alloy::Velocity(3pm)
All times are GMT -4. The time now is 06:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy