From: "Rob Coops" <rco...@gmail.com>

On Mon, Oct 29, 2012 at 9:18 AM, Shlomi Fish <shlo...@shlomifish.org> wrote:

> On Mon, 29 Oct 2012 10:09:53 +0200
> Shlomi Fish <shlo...@shlomifish.org> wrote:
>
> > Hi Octavian,
> > On Sun, 28 Oct 2012 17:45:15 +0200
> > "Octavian Rasnita" <orasn...@gmail.com> wrote:
> > > From: "Shlomi Fish" <shlo...@shlomifish.org>
> > > Hi Octavian,
...

> OK, after a short amount of investigation, I found that this program works:
>
> [CODE]
>
> use strict;
> use warnings;
>
> use XML::LibXML::Reader;
>
> my $xml = 'Lexems.xml';
>
> my $reader = XML::LibXML::Reader->new( location => $xml ) or die "cannot
> read
> $xml";
>
> while ( $reader->nextElement( 'Lexem' ) ) {
>     my $id = $reader->getAttribute( 'id' ); #works fine
>
>     my $doc = $reader->copyCurrentNode(1);
>     my $timestamp = $doc->getElementsByTagName( 'Timestamp' );
>     my @lexem_text = $doc->getElementsByTagName( 'Form' );
> }
>
> [/CODE]
>
> Note that you can also use XPath for looking up XML information.
>
> Regards,
>
>         Shlomi Fish
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/


> A little late I know but still...


Unfortunately it is not so late. :-)


> LibXML was my saviour and using XPath was the fastest solution. Though it is 
> possible to
do the DOM thing you end up with the DOM being translated to XPath under
the hood (at least the performance seemed to indicate that). After a lot of
testing and using pretty much any XML parser I could find using LibXML and
XPath was really the fastest.
If you are going for speed then you will want to avoid any copy operations
you can and you will want to as much as possible use references. Because
even though a memory copy of some 100 bytes is a very fast operation on a
few million files the the little time it takes kind of adds up to a lot
longer then you would like it to.


**
Can you gave or point me to some examples of using XPath with XML::LibXML?

I tried to use XML::XPath but it tries to load the entire document in memory so 
it is not a good way.

Octavian


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to