Sponsored Content
Full Discussion: Convert XML to CSV format
Top Forums Shell Programming and Scripting Convert XML to CSV format Post 302325224 by kumar04 on Saturday 13th of June 2009 06:49:32 PM
Old 06-13-2009
Convert XML to CSV format

Can any one give the idea on this, please.


I have the following XML file and wants to convert into CSV(comma separated value) format.
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'>
<Waveset>
<Object name='ra8736'>
  <Attribute name='ADDRESS' value='N'/>
  <Attribute name='AVAILABLE' value='Y'/>
  <Attribute name='DOB' value='19790608'/>
  <Attribute name='DEPARTMENT'>
    <List>
      <String>A</String>
      <String>B</String>
      <String>C</String>
    </List>
  </Attribute>
  <Attribute name='EMAIL' value='Y'/>
  <Attribute name='EXTERNAL' value='ra8736'/>
  <Attribute name='FIRSTNAME' value='Ta'/>
  <Attribute name='LASTNAME' value='Batt'/>
  <Attribute name='PASSWD' value='6378ar'/>
  <Attribute name='PHONE' value='N'/>
  <Attribute name='USERID' value='ra8736'/>
  <Attribute name='password'>
    <EncryptedData>1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|3Vny+ukWUEPnat0v7Z+5vA==</EncryptedData>
  </Attribute>
</Object>
<Object name='ug7444'>
  <Attribute name='ADDRESS' value='N'/>
  <Attribute name='AVAILABLE' value='Y'/>
  <Attribute name='DOB' value='19320101'/>
  <Attribute name='DEPARTMENT' value='E'/>
  <Attribute name='EXTERNAL' value='ug7444'/>
  <Attribute name='FIRSTNAME' value='Zel'/>
  <Attribute name='LASTNAME' value='dee'/>
  <Attribute name='PASSWD' value='4447gu'/>
  <Attribute name='USERID' value='ug7444'/>
  <Attribute name='password'>
    <EncryptedData>1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|Lq/Ql84BRK651SXD9xk1KA==</EncryptedData>
  </Attribute>
</Object>
<Object name='vb9838'>
  <Attribute name='password'>
    <EncryptedData>1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|JFQ3UBXuwAWDUwpSPn+cRw==</EncryptedData>
  </Attribute>
</Object>
</Waveset>

The CSV format of each object from the above XML file should look like the following;

Code:
id|ADDRESS|AVAILABLE|DOB|DEPARTMENT|EMAIL|EXTERNAL|FIRSTNAME|LASTNAME|PASSWD|PHONE|USERID|password
ra8736|N|Y|19790608|A,B,C|Y|ra8736|Ta|Batt|6378ar|N|ra8736|1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|3Vny+ukWUEPnat0v7Z+5vA==
ug7444|N|Y|19320101|E||ug7444|Zel|dee|4447gu||ug7444|1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|Lq/Ql84BRK651SXD9xk1KA==
vb9838||||||||||||1EBAA6BFE64E7639:5419E216:11B575EA443:-7FFB|JFQ3UBXuwAWDUwpSPn+cRw==

Could you please help me how can I convert XML file to CSV in perl? If you have a perl sample code, that will be a great help.

Thanks for your help in advance.

-Kumar

Last edited by kumar04; 06-16-2009 at 02:19 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to convert XML to CSV

Apologies if this has already been covered in this site somewhere, I did try looking but without any success. I am new to the whole XML thing, very late starter, and have a requirement to convert an XML fiule to a CSV fomat. I am crrently working on a Solaris OS. Does anyone have any suggestions,... (2 Replies)
Discussion started by: rossingi_33
2 Replies

2. Shell Programming and Scripting

Convert a csv file to an xls format

Hi, I have a file coming in xxx.txt(csv format) i do some work on it and i need to send out as a .xls format. Is there any way there is some code i can use in my script to convert this? I'm struggling on this. Thanks (11 Replies)
Discussion started by: Pablo_beezo
11 Replies

3. Shell Programming and Scripting

convert files into csv format using perl

Hi all perl gurus, I need your help to get the desired output in perl. I have a file which has text in it in the format Connection request start timestamp = 12/08/2008 00:58:36.956700 Connect request completion timestamp = 12/08/2008 00:58:36.959729 Application idle time ... (10 Replies)
Discussion started by: azs0309
10 Replies

4. Shell Programming and Scripting

Help needed to convert delimited to CSV format

I have a file with the data as follows.. FILE 1|#START|Jan 22 15:03 FILE 1|#END|Jan 22 16:06 FILE 2|#START|Jan 22 5:15 FILE 2|#END|Jan 22 5:25 FILE 3|#START|Jan 22 07:03 FILE 3|#END|Jan 22 08:15 FILE 4|#START|Jan 22 16:09 FILE 4|#END|Jan 22 16:55 FILE 1|#START|Jan 22 18:15 FILE... (5 Replies)
Discussion started by: karthikd214
5 Replies

5. Shell Programming and Scripting

Convert the below file to csv format

Hi , i want to change this question, i will post soon.. (6 Replies)
Discussion started by: srikanth2567
6 Replies

6. UNIX for Dummies Questions & Answers

urgent help to convert xml to xsl or csv

Urgent help to transfer data from .xml to xl sheet where each attribute and value goes into seperate column.Please help me with the command.Please help Thanks Uma (9 Replies)
Discussion started by: umapearl
9 Replies

7. Shell Programming and Scripting

awk convert xml to csv

Hi, I have an xml file and I want to convert it with awk in to a csv file Test.xml <Worksheet ss:Name="Map1"> <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60"> <Row> <Cell><Data... (6 Replies)
Discussion started by: research3
6 Replies

8. Shell Programming and Scripting

Convert xml to csv

I need to convert below xml code to csv. I searched other posts as well but this post (_https://www.unix.com/shell-programming-scripting/174417-extract-parse-xml-data-statistic-value-csv.html) gives "sed command garbled" error. As of now I have written a long script to do it, but can it be done with... (7 Replies)
Discussion started by: dineshydv
7 Replies

9. Shell Programming and Scripting

How to convert xml to csv ?

I am in need of converting billions of XML into csv file to load data to DB, i have found the below code in perl but not sure why it's not working properly. CODE: #!/usr/bin/perl # Script to illustrate how to parse a simple XML file # and pick out all the values for a specific element, in... (1 Reply)
Discussion started by: rspwilliam
1 Replies

10. Shell Programming and Scripting

Convert XML to CSV using awk or shell script

Hello, I am working on a part of code where I need a awk or shell script to convert the given XML file to CSV or TXT file. There are multiple xml files and of different structure, so a single script is required for converting data. I did find a lot of solutions in the forum but... (16 Replies)
Discussion started by: Rashmitha
16 Replies
XML::Handler::CanonXMLWriter(3) 			User Contributed Perl Documentation			   XML::Handler::CanonXMLWriter(3)

NAME
XML::Handler::CanonXMLWriter - output XML in canonical XML format SYNOPSIS
use XML::Handler::CanonXMLWriter; $writer = XML::Handler::CanonXMLWriter OPTIONS; $parser->parse(Handler => $writer); DESCRIPTION
"XML::Handler::CanonXMLWriter" is a PerlSAX handler that will return a string or write a stream of canonical XML for an XML instance and it's content. "XML::Handler::CanonXMLWriter" objects hold the options used for writing the XML objects. Options can be supplied when the the object is created, $writer = new XML::Handler::CanonXMLWriter PrintComments => 1; or modified at any time before calling the parser's `"parse()"' method: $writer->{PrintComments} = 0; OPTIONS
IOHandle IOHandle contains a handle for writing the canonical XML to. If an IOHandle is not provided, the canonical XML string will be returned from `"parse()"'. PrintComments By default comments are not written to the output. Setting comment to a true value will include comments in the output. AUTHOR
Ken MacLeod, ken@bitsko.slc.ut.us SEE ALSO
perl(1), PerlSAX James Clark's Canonical XML definition <http://www.jclark.com/xml/canonxml.html> perl v5.12.1 2003-10-21 XML::Handler::CanonXMLWriter(3)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy