Need help in creating a Unix Script to parse xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in creating a Unix Script to parse xml file
# 8  
Old 04-11-2008
Thanks a lot....

I will try with the awk code given but, as a newbee i am not very sure what the code does. If you can explain me in brief that helps me a lot.

A little change in the requirement. The input and output are given as below. I would be gr8 if anyone can spare some time to help me on this. A unix script(.ksh or .sh) to parse the input xml file and generate an output file in the format as given below.

Input File:

<Transaction 1>
<first>a</first>
<second>b</second>
</Transaction1>
<Transaction 2>
<first>c</first>
<second>d</second>
</Transaction2>

The output should be in a new file in 2 seperate lines.

Output:
a,b
c,d
# 9  
Old 04-11-2008
The sample XML presented is not valid XML. XML cannot include a free-standing "&", it has to be written as "&amp;".

With this correction in place the following XSL stylesheet will produce the desired output.
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="gDSNError">
<xsl:value-of select="errorCode"/> <xsl:value-of select="errorDescription"/> <xsl:value-of select="errorDateTime"/>
</xsl:template>
</xsl:stylesheet>

# 10  
Old 07-29-2008
hi i need one help i have an XML file i amtrying to parse it to extract attributes and their values using shell script
<?xml version="1.0" encoding="UTF-8" ?>
- <raml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="raml21.xsd">
- <cmData type="actual" scope="all" name="plan_file">
- <header>
<log dateTime="2008-07-28T11:21:00" action="created" />
</header>
</cmdata>
</raml>

the output should be
log datetime 2008-07-28T11:21:00
action created

please help me at the earliest
# 11  
Old 07-29-2008
Code:
$ sed -n '/<log/p' file | sed -e 's/[<\/>]//g' -e 's/ \(action\)/\
> \1/'
log dateTime="2008-07-28T11:21:00"
action="created"
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse xml file

I am trying to create a shell script that will parse an xml file (file attached). awk '/Id v=/ { print }' Test.xml | sed 's!<Id v=\"\(.*\)\"/>!\1!' > output.txt An output.txt file is created but it is empty. It should contain the value 222159 in it. Thanks. (7 Replies)
Discussion started by: cmccabe
7 Replies

2. UNIX for Dummies Questions & Answers

Parse xml file

HI Guys, Input .XML <xn:MeContext id="L0307"> <xn:ManagedElement id="1"> <xn:VsDataContainer id="1"> <xn:attributes> <xn:vsDataType>vsDataENodeBFunction</xn:vsDataType> ... (3 Replies)
Discussion started by: pareshkp
3 Replies

3. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

4. Shell Programming and Scripting

parse xml file

Hello all, Given the following extract from a xml file with multiple <JOB> .... </JOB> entries <JOB APPLICATION="APP" APR="0" AUG="0" AUTHOR="AUT" AUTOARCH="0" CMDLINE="/tmp/test1 %%var" CONFIRM="1" CREATION_DATE="20100430" CREATION_TIME="130739" ... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

Parse XML file in shell script

Hi Everybody, I have an XML file containing some data and i want to extract it, but the specific issue in my file is that the data is repeated some times like the following example : <section1> <subsection1> X=... Y=... Z=... <\subsection1> <subsection2> X=... Y=... Z=...... (2 Replies)
Discussion started by: yassine
2 Replies

6. Shell Programming and Scripting

Need to Parse XML from bash script

I am completely new to bash scripting and now need to write a bash script that would parse a XML file and take out values from specific tags. I tried using xsltproc, xml_grep commands. But the issue is that the XML i am trying to parse is not UTF 8. so those commands are unable to parse my XML's... (4 Replies)
Discussion started by: shivashankar.g
4 Replies

7. Shell Programming and Scripting

How can I parse xml file?

How can I parse file containing xml ? I am sure that its best to use perl - but my perl is not very good - can someone help? Example below contents of file containing the xml - I basically want to parse the file and have each field contained in a variable.. ie. I want to store the account... (14 Replies)
Discussion started by: frustrated1
14 Replies

8. Shell Programming and Scripting

Parse a string in XML file using shell script

Hi! I'm just new here and don't know much about shell scripting. I just want to ask for help in creating a shell script that will parse a string or value of the status in the xml file. Please sample xml file below. Can you please help me create a simple script to get the value of status? Also it... (46 Replies)
Discussion started by: ayhanne
46 Replies

9. Shell Programming and Scripting

Parse XML file

Hi, I need to parse the following XML data enclosed in <a> </a> XML tag using shell script. <X> ..... </X> <a> <b> <c>data1</c> <c>data2</c> </b> <d> <c>data3</c> </d> </a> <XX> ... </XX> (5 Replies)
Discussion started by: viki
5 Replies

10. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies
Login or Register to Ask a Question