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, > > > > > > > > Hi Shlomi, > > > > I tried to use XML::LibXML::Reader which uses the pool parser, and I read > > that: > > > > "" > > However, it is also possible to mix Reader with DOM. At every point the > > user may copy the current node (optionally expanded into a complete > > sub-tree) from the processed document to another DOM tree, or to > > instruct the Reader to collect sub-document in form of a DOM tree > > "" > > > > So I tried: > > > > use XML::LibXML::Reader; > > > > my $xml = 'path/to/xml/file.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->document; > > > > my $timestamp = $doc->getElementsByTagName( 'Timestamp' ); #Doesn't > > work well > > my @lexem_text = $doc->getElementsByTagName( 'Form' ); #Doesn't work > > fine > > > > } > > > > I'm not sure you should do ->document. I cannot tell you off-hand how to do it > right, but I can try to investigate when I have some spare cycles. > 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/ List of Text Processing Tools - http://shlom.in/text-proc Sophie: Let’s suppose you have a table with 2^n cups… Jack: Wait a second! Is ‘n’ a natural number? Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/