Sponsored Content
Full Discussion: Help to convert XML to CSV
Top Forums Shell Programming and Scripting Help to convert XML to CSV Post 302169714 by fpmurphy on Friday 22nd of February 2008 06:18:54 AM
Old 02-22-2008
This is not as simple to do as converting from CSV to XML.

First you have to remove the declarations, root element and comments, then for each "record" figure out which elements should be columns and which "record" has the greatest number of columns. Unless it is a very simple XML document, it may not be easily parsed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sample Unix script file to convert .xml to .csv

Dear all, Can you send me a script file the changes .xml to .csv file. Thanks, Srinivasa (4 Replies)
Discussion started by: srinivasaphani
4 Replies

2. Shell Programming and Scripting

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. <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'> <Waveset> <Object name='ra8736'> <Attribute name='ADDRESS'... (2 Replies)
Discussion started by: kumar04
2 Replies

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

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

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

6. Shell Programming and Scripting

convert huge .xml file in .csv with specific column.

I have huge xml file in server and i want to convert it to .csv with specific column ... i have search in blog but i didn't get any usefully command. Thanks in advance (1 Reply)
Discussion started by: pareshkp
1 Replies

7. Shell Programming and Scripting

Convert XML file to CSV file

Hi Guys, I am new to Shell scripting and need to convert an XML files to a CSV file. My actual problem is that XML file loading is taking hours and I have decided to convert the XML structure to row based data in a CSV file. My XML file: Message846 can repeat within main loop and... (1 Reply)
Discussion started by: qamar.shahbaz
1 Replies

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

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

10. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies
LibXML(3pm)						User Contributed Perl Documentation					       LibXML(3pm)

NAME
XML::SimpleObject::LibXML - Perl extension allowing a simple(r) object representation of an XML::LibXML DOM object. SYNOPSIS
use XML::SimpleObject::LibXML; # Construct with the key/value pairs as argument; this will create its # own XML::LibXML object. my $xmlobj = new XML::SimpleObject(XML => $XML); # ... or construct with the parsed tree as the only argument, having to # create the XML::Parser object separately. my $parser = new XML::LibXML; my $dom = $parser->parse_file($file); # or $parser->parse_string($xml); my $xmlobj = new XML::SimpleObject::LibXML ($dom); my $filesobj = $xmlobj->child("files")->child("file"); $filesobj->name; $filesobj->value; $filesobj->attribute("type"); %attributes = $filesobj->attributes; @children = $filesobj->children; @some_children = $filesobj->children("some"); @children_names = $filesobj->children_names; DESCRIPTION
This is a short and simple class allowing simple object access to a parsed XML::LibXML tree, with methods for fetching children and attributes in as clean a manner as possible. My apologies for further polluting the XML:: space; this is a small and quick module, with easy and compact usage. Some will rightfully question placing another interface over the DOM methods provided by XML::LibXML, but my experience is that people appreciate the total simplicity provided by this module, despite its limitations. USAGE
$xmlobj = new XML::SimpleObject::LibXML($parser->parse_string($XML)) $parser is an XML::LibXML object. After creating $xmlobj, this object can now be used to browse the XML tree with the following methods. $xmlobj->child('NAME') This will return a new XML::SimpleObject::LibXML object using the child element NAME. $xmlobj->children('NAME') Called with an argument NAME, children() will return an array of XML::SimpleObject::LibXML objects of element NAME. Thus, if $xmlobj represents the top-level XML element, 'children' will return an array of all elements directly below the top-level that have the element name NAME. $xmlobj->children Called without arguments, 'children()' will return an array of XML::SimpleObjects::LibXML objects for all children elements of $xmlobj. Unlike XML::SimpleObject, XML::SimpleObject::LibXML retains the order of these children. $xmlobj->children_names This will return an array of all the names of child elements for $xmlobj. You can use this to step through all the children of a given element (see EXAMPLES), although multiple elements of the same name will not be identified. Use 'children()' instead. $xmlobj->value If the element represented by $xmlobj contains any PCDATA, this method will return that text data. $xmlobj->attribute('NAME') This returns the text for an attribute NAME of the XML element represented by $xmlobj. $xmlobj->attributes This returns a hash of key/value pairs for all elements in element $xmlobj. EXAMPLES
Given this XML document: <files> <file type="symlink"> <name>/etc/dosemu.conf</name> <dest>dosemu.conf-drdos703.eval</dest> </file> <file> <name>/etc/passwd</name> <bytes>948</bytes> </file> </files> You can then interpret the tree as follows: my $parser = new XML::LibXML; my $xmlobj = new XML::SimpleObject::LibXML ($parser->parse_string($XML)); print "Files: "; foreach my $element ($xmlobj->child("files")->children("file")) { print " filename: " . $element->child("name")->value . " "; if ($element->attribute("type")) { print " type: " . $element->attribute("type") . " "; } print " bytes: " . $element->child("bytes")->value . " "; } This will output: Files: filename: /etc/dosemu.conf type: symlink bytes: 20 filename: /etc/passwd bytes: 948 You can use 'children()' without arguments to step through all children of a given element: my $filesobj = $xmlobj->child("files")->child("file"); foreach my $child ($filesobj->children) { print "child: ", $child->name, ": ", $child->value, " "; } For the tree above, this will output: child: bytes: 20 child: dest: dosemu.conf-drdos703.eval child: name: /etc/dosemu.conf Using 'children_names()', you can step through all children for a given element: my $filesobj = $xmlobj->child("files"); foreach my $childname ($filesobj->children_names) { print "$childname has children: "; print join (", ", $filesobj->child($childname)->children_names), " "; } This will print: file has children: bytes, dest, name By always using 'children()', you can step through each child object, retrieving them with 'child()'. AUTHOR
Dan Brian <dan@brians.org> SEE ALSO
perl(1), XML::SimpleObject, XML::Parser, XML::LibXML. perl v5.10.1 2010-01-03 LibXML(3pm)
All times are GMT -4. The time now is 10:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy