perl and xml parsing
am 16.09.2006 02:19:07 von John Gregory
I am new to both perl and xml. I need to parse through an
xml file and extract data from certain elements. I know I should
probably use the XML::SAX cpan module but haven't been able
to find any usable examples. I've posted this to c.l.xml, but thought
this may be the more appropriate group to pose this question.
Any help would be greatly appreciated.
Thanks,
John
Re: perl and xml parsing
am 17.09.2006 00:48:11 von mgarrish
John Gregory wrote:
> I am new to both perl and xml. I need to parse through an
> xml file and extract data from certain elements. I know I should
> probably use the XML::SAX cpan module but haven't been able
> to find any usable examples. I've posted this to c.l.xml, but thought
> this may be the more appropriate group to pose this question.
>
Anything wrong with the examples in the documentation? A sax parser
just fires events based on the text being parsed. It's not terribly
complicated, although the syntax may appear that way at first. You
might want to try xml.com. There are a number of useful articles on
perl and xml there, though I'm too lazy to search for them for you... :
)
In terms of alternatives, I'm more partial to XML::Libxml, but you may
not have the luxury of being able to read the entire file into memory.
XML::Simple is only as simple as your data, so if you have any
complexity I'd write it off, but if you're looking for an easy way to
get your data into a usable perl data structure it does work wonders (I
tend to only use it for config-type files though). There's also
XML::Twig, but I haven't found any compelling reason to go to it over
the big two and XML::Simple, so I won't hazard any comments on it.
Take a stab at writing your own SAX parser code and if you have any
problems you need help with you're welcome to post again, although I'd
recommend comp.lang.perl.misc. Comp.lang.perl is a dead newsgroup and
alt.perl hasn't seen much traffic in about 4 or 5 years, whereas there
are at least a few regulars in clpm who use XML and Perl extensively.
Matt
Re: perl and xml parsing
am 18.09.2006 22:03:01 von Jim Gibson
In article <1158446891.164037.251750@d34g2000cwd.googlegroups.com>,
wrote:
> John Gregory wrote:
>
> > I am new to both perl and xml. I need to parse through an
> > xml file and extract data from certain elements. I know I should
> > probably use the XML::SAX cpan module but haven't been able
> > to find any usable examples. I've posted this to c.l.xml, but thought
> > this may be the more appropriate group to pose this question.
> >
> In terms of alternatives, I'm more partial to XML::Libxml, but you may
> not have the luxury of being able to read the entire file into memory.
> XML::Simple is only as simple as your data, so if you have any
> complexity I'd write it off, but if you're looking for an easy way to
> get your data into a usable perl data structure it does work wonders (I
> tend to only use it for config-type files though). There's also
> XML::Twig, but I haven't found any compelling reason to go to it over
> the big two and XML::Simple, so I won't hazard any comments on it.
XML::Twig lets you define handlers for specific-element types, so if
you are just interested in certain elements it can simplify your
program. It will also let you parse and copy/modify an XML file that is
too big to fit into memory, but, thankfully, I have never encountered
such a beast (and hope never to do so).
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Re: perl and xml parsing
am 19.09.2006 13:46:10 von hc.d2rk
Some good cpan modules for working parsing XML:
XML::Simple ; XML::Parser ; XML::LibXML ; XML::PYX ; XML::SAX
Some documentation: http://perl-xml.sourceforge.net/ ,
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html