Output as XML File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output as XML File
# 1  
Old 05-22-2012
Output as XML File

Hello All,

I am running a shell script, which in turn runs a perl script. When this perl script runs successfully, the output is generated as an XML file. The following is a snippet of my code:

Code:
 
....
....
...
if [ condition is true] ;
then
    perl myScript.pl
    echo "<statistics>"
    echo " <update>YES</update>"
    echo " <date>`date +\%m\%d\%Y.\%H\%M\%S`</date>"
    echo " <id>$id</id>"
    echo " <name>$name</name>"
    echo "</statistics>" 
....
...
..

To run this shell script (and redirect the output in an xml file)
Code:
 
./test.sh ARG1 >> output.xml

The output XML file does not get displayed properly, since it does not have a 'parent tag'. If I manually add this tag, I can display the file:
Code:
 
 
XML File (does not displays without a parent tag <master_log>):
<statistics>
 <update>NO</update>
 <date>05202012.180001</date>
 <id>my_Local_1</id>
 <name>AAA</name>
</statistics>
<statistics>
 <update>NO</update>
 <date>05212012.134043</date>
 <id>LOCAL_MY_2</id>
 <name>XXX</name>
</statistics>
...
..
.

How can I automatically add tags <master_log></master_log>, without having to do so manually? And also without affecting the log append procedure everytime the script runs successfully?
# 2  
Old 05-22-2012
That is going to be most difficult because you'll need to be inserting inside those tags every time you do it, wouldn't you? That would quickly become a huge amount of work every time you want to just append, since you need to hunt for the last line and delete it before you do so...

Myself, I'd just keep the log as a list of <statistics> elements, and only wrap it when I need to by doing

Code:
( echo "<master_log>" ; cat logfile ; echo "</master_log>" ) > newfile

A rare useful use of cat on a single file Smilie
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-22-2012
Yes, you are right. It is a difficult task. Your way sounds good, and it works.

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

Comparing delta values of one xml file in other xml file

Hi All, I have two xml files. One is having below input <NameValuePair> <name>Daemon</name> <value>tcp:7474</value> </NameValuePair> <NameValuePair> <name>Network</name> <value></value> </NameValuePair> ... (2 Replies)
Discussion started by: sharsour
2 Replies

4. Shell Programming and Scripting

Help in parsing XML output file in perl.

Hi I have an XML output like : <?xml version="1.0" encoding="ISO-8859-1" ?> - <envelope> - <body> - <outputGetUsageSummary> - <usgSumm rerateDone="5"> - <usageAccum accumId="269" accumCaptn="VD_DP_AR" inclUnits="9999999.00" inclUnitsUsed="0.00" shared="false" pooled="false"... (7 Replies)
Discussion started by: rkrish
7 Replies

5. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

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

7. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

8. Shell Programming and Scripting

How to get input xml file as XMLout. output.

Hi , I am trying to get an reference of a XML formatted data using XML::Simple::XMLin and again trying to retrive the XML data as it was before using XML::Simple::XMLout. But finding a deviation in the format can any pls help me out. Input file sr.xml <?xml version="1.0"... (0 Replies)
Discussion started by: srkelect
0 Replies

9. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

10. Shell Programming and Scripting

Remove xmlns from xml output file

Hi, I have the xml output file which contents the namespace xmlns. I would like to remove that line <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> I would like to remove line... (1 Reply)
Discussion started by: ca_sr2274
1 Replies
Login or Register to Ask a Question