How can I replace data in between xml tags to required format?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I replace data in between xml tags to required format?
# 1  
Old 05-15-2013
How can I replace data in between xml tags to required format?

Hi All,

I have a requirement to change the data in xml file to required format.
Below is the scenario.

Please find the attached Xml file which contains data that I need to convert..


Code:
 
<ReleaseIndicatorList><ReleaseIndicator>Alternative Content||Animated|||IMAX|OpenCaption||SensoryFriendlyFilm||3D</ReleaseIndicator></ReleaseIndicatorList>
<ReleaseIndicatorList><ReleaseIndicator>Alternative Content||Animated|||IMAX|||SensoryFriendlyFilm||3D</ReleaseIndicator></ReleaseIndicatorList>
<ReleaseIndicatorList><ReleaseIndicator>||||||||||</ReleaseIndicator></ReleaseIndicatorList>



I always get 10 pipes(|) in between


Code:
 
<ReleaseIndicator>||||||||||</ReleaseIndicator>



If I have any data for 10 fields I will get data in between pipes, if not that will be empty.

My requirement is If have any data in between pipes I need to replace that with below format.


Code:
 
Existed record 
 
<ReleaseIndicatorList><ReleaseIndicator>Alternative Content||Animated|||IMAX|OpenCaption||SensoryFriendlyFilm||3D</ReleaseIndicator></ReleaseIndicatorList>
 
Required format :
 
<ReleaseIndicatorList><ReleaseIndicator>AlternativeContent</ReleaseIndicator><ReleaseIndicator>Animated</ReleaseIndicator><ReleaseIndicator>IMAX</ReleaseIndicator><ReleaseIndicator>OpenCaption</ReleaseIndicator>
<ReleaseIndicator>SensoryFriendlyFilm</ReleaseIndicator><ReleaseIndicator>3D</ReleaseIndicator></ReleaseIndicatorList>



If I did not have any data in between pipes I need to remove that record

Code:
 
Existed Record :
 
<ReleaseIndicatorList><ReleaseIndicator>||||||||||</ReleaseIndicator></ReleaseIndicatorList>


Requirement :

I want to remove total above record.

Is my requirement is possible to handle..If anyone know the solution Please help me.

Thanks in Advance..

Last edited by Prathyu; 05-15-2013 at 04:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting data between continuous non empty xml tags

Hi, I need help in extracting only the phone numbers between the continuous non empty xml tags in unix. I searched through a lot of forum but i did not get exact result for my query. Please help Given below is the sample pipe delimited file. I have a lot of tags before and after... (6 Replies)
Discussion started by: zen01234
6 Replies

2. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

3. UNIX for Advanced & Expert Users

Shell Script to read XML tags and the data within that tag

Hi unix Gurus, I am really new to Unix Scripting. Please help me to create a shell script which reads the xml file and from that i need to fetch a particular information. For example <SOURCE BUSINESSNAME ="" DATABASETYPE ="Teradata" DBDNAME ="DWPROD3" DESCRIPTION ="" NAME... (2 Replies)
Discussion started by: SmilePlease
2 Replies

4. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1="http://example.com/config"> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

5. Shell Programming and Scripting

print xml data without the tags.

Hi All, I'm trying to extract data from an xml file but without the codes. I've achieved it but i was wondering if there's a better way to do this. sample data: $ cat xmlfile <code> <to>tove</to> <from>jani</from> <heading>reminder</heading> <body>dont forget me</body> </code> ... (4 Replies)
Discussion started by: Irishboy24
4 Replies

6. Shell Programming and Scripting

Data between XML Tags

<?xml version="1.0" encoding="iso-8859-1" ?> <TABLE> <TEST> <ID> 123 </ID> <name> abc </name> </TEST> <TEST> <ID> 123 </ID> <name> abc2 </name> </TEST> </TABLE> <TABLE> <TEST> <ID> 456 </ID> <name> def </name> </TEST> <TEST> ... (8 Replies)
Discussion started by: eskay
8 Replies

7. Shell Programming and Scripting

How to update data between xml tags

Is there a way to modify Non Null data between <host> and </host> tags to a new value ?- may be using sed/awk? I tried this sed 's|.*<host>\(?*\)</host>.*|\<host>xxx</host>|' but it is updating the host which has null value - want opposite of this - Thanks in advance for you help!! For... (2 Replies)
Discussion started by: harry_todd
2 Replies

8. Shell Programming and Scripting

how to get data from xml files tags(from data tags)

i have a file like <fruits> <apple>redcolor<\apple> <bana:rolleyes:na>yellow color and it is<\banana> </fruits> i need a text between apple and bannana ans so on.... how to read a text between a tags it multiple tags with differnt names (9 Replies)
Discussion started by: pvr_satya
9 Replies

9. Shell Programming and Scripting

extract specific data from xml format file.

Hi, I need to extract the start time value (bold, red font) under the '<LogEvent ID="Timer Start">' tag (black bold) from a file with the following pattern. There are other LogEventIDs listed in the file as well, making it harder for me to extract out the specific start time that I need. . .... (7 Replies)
Discussion started by: 60doses
7 Replies

10. UNIX for Dummies Questions & Answers

Removing leading and trailing spaces of data between the tags in xml.

I am having xml document as below. <transactionid> 00 </transactionid> <tracknumber> 0 </tracknumber> <key> N/A </key> But the data contains leading and trailing spaces between the tags. Please let me know how can i remove these leading and trailing spaces between the tags.... (2 Replies)
Discussion started by: jhmr7
2 Replies
Login or Register to Ask a Question