Gossamer Forum
Home : General : Perl Programming :

Saving data to an xml file using perl

Quote Reply
Saving data to an xml file using perl
Hi...

Ok, here's my problem. I'm using regular expressions to extract certain data from a website. Now I'd like to sort out the data collected in an xml file. i've never done that before, and have no idea on how to go about doing it. Could someone supply me with some example code of how to write an xml file using perl? Thank you sooo much!! :)
Quote Reply
Re: [q8tygirl] Saving data to an xml file using perl In reply to
Using XML::Simple or XML::Dumper will be probably be the easiest way to do that. They will dump a Perl data structure to XML. Check the docs on CPAN for examples: http://search.cpan.org/...le/lib/XML/Simple.pm & http://search.cpan.org/...XML-Dumper/Dumper.pm.

~Charlie
Quote Reply
Re: [Chaz] Saving data to an xml file using perl In reply to
Thanks, it looks easy enough. However, when i tried using it, i got the following error:

Can't locate XML/Simple.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 .)

The thing is, I found a file Simple.pm under an XML/ directory under the cgi-bin directory i'm working on. Do I need to change something other than just writing a simple

use XML::Simple;

Thanks.
Quote Reply
Re: [q8tygirl] Saving data to an xml file using perl In reply to
That means XML::Simple isn't installed on your server.

You will need to get your host to install that (or give it a go yourself, in SSH.. with perl -MCPAN -e 'install XML::Simple').

You may also need XML::Parser installed, as some parts of XML::Simple rely on this (AFAIK).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [q8tygirl] Saving data to an xml file using perl In reply to
As long as XML::Parser is already installed all you should need to do is add use lib '/path/to/xml_dir'l above the use XML::Simple; line. I don't think XML::Simple has any xs code in it so it should work like that. Like Andy mentioned, it does need XML::Parser though. If XML::Parser is not installed you will need to install that or have your host install it. It does need to be compiled because of the xs code dependency.

~Charlie
Quote Reply
Re: [Chaz] Saving data to an xml file using perl In reply to
Thank you both so much! It's working beautifully! :)