Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 17522
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: MIROD [...] cpan.org
Requestors: Harco.de.Hilster [...] ATConsultancy.nl
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.23
Fixed in: 3.24



Subject: flush() repeats the last input line
Hi Michel, First of all thanks for XML::Twig. I use it to process large XML files with database records. I have a problem with flush which I think is a bug. I use flush in my handler and a final flush at the end as described in the documentation. Sometimes I get the correct result and sometimes I get the last tag twice. It depends on how often flush is called. A simple example shows that calling flush more than once repeats the last input line. My handler either converts a record + flush or ignores a record + no flush. I cannot leave out the flush in the script, because than I sometimes miss the last tag. Is this a bug or a feature ;-) ? Thanxs, Harco Input: <?xml version="1.0" encoding="UTF-8" ?> <records xmlns:dbi='http://axkit.org/NS/xml-generator-dbi'> <record> <drivergroup>DCE ONG</drivergroup> <usd_id>103995</usd_id> <status>0</status> <usd_modtime>1139308221</usd_modtime> </record> <record> <drivergroup>Network WAN Planning</drivergroup> <usd_id>832605</usd_id> <status>0</status> <usd_modtime>1139308424</usd_modtime> </record> </records> script: #!/usr/bin/perl -w use XML::Twig; my ($file, $elt)= @ARGV; my $t= XML::Twig->new( twig_handlers => { $elt => sub {$_[0]->flush; print "\n[flushed here]\n";} }); $t->parsefile( $file, ErrorContext => 2); $t->flush; # in my script, depending on the flush in the handler needed or not needed $t->flush; # not in my script, but shows that flushing twice is harmfull $t->flush; # not in my script print "\n"; output: ?xml version="1.0" encoding="UTF-8"?> <records xmlns:dbi="http://axkit.org/NS/xml-generator-dbi"><record><drivergroup>DCE ONG</drivergroup><usd_id>103995</usd_id><status>0</status><usd_modtime>1139308221</usd_modtime></record> [flushed here] <record><drivergroup>Network WAN Planning</drivergroup><usd_id>832605</usd_id><status>0</status><usd_modtime>1139308424</usd_modtime></record> [flushed here] </records></records></records>
Subject: Re: [rt.cpan.org #17522] flush() repeats the last input line
Date: Tue, 07 Feb 2006 16:47:05 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: Michel Rodriguez <mirod [...] xmltwig.com>
Guest via RT wrote: Show quoted text
> Tue Feb 07 10:09:30 2006: Request 17522 was acted upon. > Transaction: Ticket created by guest > Queue: XML-Twig > Subject: flush() repeats the last input line > Owner: Nobody > Requestors: Harco.de.Hilster@ATConsultancy.nl > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=17522 > > > > Hi Michel, > > First of all thanks for XML::Twig. I use it to process large XML files > with database records. I have a problem with flush which I think is a bug. > > I use flush in my handler and a final flush at the end as described in > the documentation. Sometimes I get the correct result and sometimes I > get the last tag twice. It depends on how often flush is called. A > simple example shows that calling flush more than once repeats the last > input line. > My handler either converts a record + flush or ignores a record + no > flush. I cannot leave out the flush in the script, because than I > sometimes miss the last tag. Is this a bug or a feature ;-) ?
Hi Harco, I'd vote for 'bug'! The code for flush got a little complicated with the introduction of the "autoflush" feature. I think I fixed it, I need to test it more thouroughly, but it seems to work on your test case. The fix is not really elegant, but I don't think anyone is going to object to 1 more field to the twig object. The updated version is on my website, at http://xmltwig.com/xmltwig/ Let me know if it works for you. Thanks -- Michel Rodriguez Perl &amp; XML xmltwig.com
Subject: Re: [rt.cpan.org #17522] flush() repeats the last input line
Date: Tue, 07 Feb 2006 17:15:33 +0100
To: bug-XML-Twig [...] rt.cpan.org
From: Harco de Hilster <harcoh [...] ATConsultancy.nl>
mirod@xmltwig.com via RT wrote: Show quoted text
> Hi Harco, > >I'd vote for 'bug'! > >The code for flush got a little complicated with the introduction of the >"autoflush" feature. > >I think I fixed it, I need to test it more thouroughly, but it seems to >work on your test case. The fix is not really elegant, but I don't think >anyone is going to object to 1 more field to the twig object. > >The updated version is on my website, at http://xmltwig.com/xmltwig/ > >Let me know if it works for you. > >Thanks > > >
Hi Michel, Wow. That is fast, and it completly fixes my problem. Thanks!! Harco -- -----------------+--------------------+------------------------------- Harco de Hilster AT Consultancy Phone: +31(0)24-3527282 Unix Consultant Toernooiveld 104 Fax: +31(0)24-3527292 6525 EC Nijmegen E-mail: harcoh@ATConsultancy.nl The Netherlands -----------------+--------------------+-------------------------------