Ask a Question related to Perl / CGI, Design and Development.
-
Ravi #1
XML to CSV Conversion
Hi All,
Does anyone have a perl script handy to show me how to convert an XML
document to CSV format ?
Thanks in advance.
Ravi Guest
-
Conversion Mac to PC
My dept. is switching from mac to pc for networking reasons. How can I convert the pagemaker 6.5 documents on the mac to indesign documents on the... -
RGB Conversion
Help! We're on a mac and changed our text in Illustrator to RGB 0/0/102, saved and closed the file. When we reopened the file, the RGB percentages... -
dxf conversion
hello, I have been using AutoCAD LT to create .dxf files which are then imported into FH MX. However, I have noticed that the size of features... -
[PHP] Mp3 Conversion, using PHP
I'm wondering if there's any crazy dude out there that would like to join me in making a class for PHP to convert Mp3's to Mp3Pro. Have you... -
A bit OT: conversion mp3 to wav
In my deb testing installation until recently I had been using a widely known procedure to convert mp3 files into wav to roast CDs. in a nutshell... -
James Willmore #2
Re: XML to CSV Conversion
On 18 Aug 2003 06:53:19 -0700
[email]anamalay@hotmail.com[/email] (Ravi) wrote:Someone has gone to the trouble of creating the XML::CSV module just> Does anyone have a perl script handy to show me how to convert an
> XML document to CSV format ?
for this purpose.
HTH
Jim
James Willmore Guest
-
trwww #3
Re: XML to CSV Conversion
[email]anamalay@hotmail.com[/email] (Ravi) wrote in message news:<2c6dd813.0308180553.382c295b@posting.google. com>...
Here is a way, using XML::XPath:> Hi All,
>
> Does anyone have a perl script handy to show me how to convert an XML
> document to CSV format ?
>
[trwww@waveright perl]# cat xml2csv.pl
#!/usr/bin/perl
use warnings;
use strict;
use XML::XPath;
my($xp) = XML::XPath->new( join('', <DATA>) );
my(@records) = $xp->findnodes( '/records/record' );
my($firstTime) = 0;
foreach my $record ( @records ) {
my(@fields) = $xp->find( './child::*', $record )->get_nodelist();
unless ( $firstTime++ ) {
print( join( ',', map { $_->getName() } @fields ), "\n");
}
print( join( ',', map { $_->string_value() } @fields ), "\n");
}
__DATA__
<records>
<record>
<id>1</id>
<name>George Foo</name>
<phone>555.666.7777</phone>
</record>
<record>
<id>2</id>
<name>Betty Bar</name>
<phone>666.777.8888</phone>
</record>
</records>
[trwww@waveright perl]# perl xml2csv.pl
id,name,phone
1,George Foo,555.666.7777
2,Betty Bar,666.777.8888
If your data has commas in it, then you can run $_->string_value()
through a filter that escapes the comma.
enjoy,
Todd W.
trwww Guest
-
James E Keenan #4
Re: XML to CSV Conversion
"James Willmore" <jwillmore@cyberia.com> wrote in message
news:20030818155810.44fe12fa.jwillmore@cyberia.com ...The shorthand description of XML::CSV is: "Perl extension converting CSV> On 18 Aug 2003 06:53:19 -0700
> [email]anamalay@hotmail.com[/email] (Ravi) wrote:>> > Does anyone have a perl script handy to show me how to convert an
> > XML document to CSV format ?
> Someone has gone to the trouble of creating the XML::CSV module just
> for this purpose.
>
files to XML". I couldn't find anything in the documentation that suggests
that this module goes the other way around.
James E Keenan Guest
-
James Willmore #5
Re: XML to CSV Conversion
"James E Keenan" <jkeen@concentric.net> wrote in message news:<bhrlrt$3eu@dispatch.concentric.net>...
You appear to be correct. How about:> "James Willmore" <jwillmore@cyberia.com> wrote in message
> news:20030818155810.44fe12fa.jwillmore@cyberia.com ...>> > On 18 Aug 2003 06:53:19 -0700
> > [email]anamalay@hotmail.com[/email] (Ravi) wrote:> >> > > Does anyone have a perl script handy to show me how to convert an
> > > XML document to CSV format ?
> > Someone has gone to the trouble of creating the XML::CSV module just
> > for this purpose.
> >
> The shorthand description of XML::CSV is: "Perl extension converting CSV
> files to XML". I couldn't find anything in the documentation that suggests
> that this module goes the other way around.
AnyData::Format::XML
-or- you could perform the same search I used to find this - go to
[url]http://search.cpan.org/[/url]
There are several XML modules listed there - some use SAX, others
Expat, others are pure Perl. I played around with XML, but have had
no real need to use it. I'd like to, because XML files can be used in
some many different ways - just have not found them time.
Or you could write your own - which I think you wanted to avoid doing.
HTH and sorry I can't be of more help - maybe someone else who uses
XML regularlly can chime in.
Jim
James Willmore Guest



Reply With Quote

