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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add the multiple lines of xml tags before a particular xml tag in a file
# 1  
Old 06-25-2012
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.

Code:
<A>testing_Location</A>
<value>LA</value>
<zone>US</zone>

<B>Region</B>
<value>Russia</value>
<zone>Washington</zone>
<C>Country</C>
<value>Canada</value>
<zone>US</zone>

In the above example, my need to add the following line of code above the <zone> tag:
Code:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>

The Output should display like:

<A>testing_Location</A>
<value>LA</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>US</zone>

<B>Region</B>
<value>Russia</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>Washington</zone>
<C>Country</C>
<value>Canada</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>US</zone>


Please help me out..

Last edited by mjavalkar; 06-25-2012 at 05:57 PM.. Reason: Update of title
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. 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

3. 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

4. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

5. 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

6. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <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> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

7. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

8. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

9. Shell Programming and Scripting

XML tag replacement from different XML file

We have 2 XML file 1. ORIGINAL.xml file and 2. ATTRIBUTE.xml files, In the ORIGINAL.xml we need some modification as <resourceCode>431048</resourceCode>under <item type="Manufactured"> tag - we need to grab the 431048 value from tag and pass it to database table in unix shell script to find the... (0 Replies)
Discussion started by: balrajg
0 Replies

10. Shell Programming and Scripting

getting multiple xml tag

sorry for the trouble...... i have this file that contains the following: 00:00:21 Queue key, Queue Name= 00:00:21 Sending Message :<EXGC-EXGU xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <trans_id>EXGC</trans_id> <sys_prefix>GSYS</sys_prefix> ... (3 Replies)
Discussion started by: forevercalz
3 Replies
Login or Register to Ask a Question