On Tue, May 11, 2010 at 6:34 PM, Jonathan Rockway <j...@jrock.us> wrote: > > * On Tue, May 11 2010, Klaus wrote: > > However, unlike XML::Twig, XML::Reader does not rely on callback > > functions to parse the XML. With XML::Reader you loop over the > > XML-document yourself and the resulting XML-elements (and/or > > XML-subtrees) are represented in text format. This style of processing > > XML is similar to the classic pattern: > > > > "open my $fh, '<', 'file.txt'; while (<$fh>) { do_sth($_); } close $fh;" > > FWIW, it's very easy to make callback-based code look like an iterator. > Here's an example script. > > use strict; > use warnings; > use feature ':5.10'; > > use Coro; > use Coro::Handle; > use Coro::Channel; > [...]
Thanks, I have never heard of "Coro", "Coro::Handle" or "Coro::Channel". Sounds interesting, I will look into it. > So I'm not sure there's a point in writing a module just to be > loop-driven instead of callback-driven; it's easy to convert > callback-based code to "blocking" code. > > When in doubt, if you are trying to write something reusable, make it > callback-driven instead of blocking. Then the consumer can easily > choose how to use it. I agree very much, it's all about informed choices. I say that the aproach should always be to use existing, long-standing, well-tested modules first before using XML::Reader. That's why I commented "...take the advice of Tad McClellan and John Bokma first..." on comp.lang.perl.misc, subject "Get XML content using XML::Twig" http://groups.google.com/group/comp.lang.perl.misc/msg/7b820ef7eac4cbab Here is the gist of the discussion: > On 21 avr, 14:35, alwaysonnet > <kalyanrajsi...<http://groups.google.com/groups/unlock?_done=/group/comp.lang.perl.misc/browse_frm/thread/cb0f941567d152b6/d88b15bb005e9edf%3Flnk%3Dgst%26q%3Dxml%253A%253Areader%26&msg=019902ffdfd1f90c> @gmail.com> wrote: > > I'm trying to parse the XML using XML::Twig Module as my XML > > could be very large to handle using XML::Simple. > [...] > On 21 avr, 15:13, Tad McClellan <ta...@seesig.invalid> wrote: > > What have you tried so far? > > If you show us your broken code we will help you fix it. > [...] > On 21 avr, 15:49, John Bokma <j...@castleamber.com> wrote: > > For very simple things like this I would (probably, based on what > > I just read) use XML::SAX or (even) XML::Parser. Regarding the > > latter, http://johnbokma.com/perl/ has some simple examples > > under "XML Processing using Perl" > [...] > On 22 avr, 11:08, Klaus <klau...@gmail.com> wrote: > > take the advice of Tad McClellan and John Bokma first. > > If, for whatever reason, you can't follow their advice, (and, for > > whatever reason, you can't use XML::Twig either) there is always > > my "shameless plug"XML::Reader: In addition to that, I learned soon after, that there exists an excellent article: "Ways to Rome: Processing XML with Perl" > On 22 avr, 11:44, <redgrittybr...@spamweary.invalid> wrote: > > For very arge XML files, the obvious approach to consider is any > > SAX parser. Perl SAX modules I've used before include > > XML::Parser and XML::SAX. Have you Googled for "Perl SAX" > > and searched CPAN for SAX? I recommend you read this > > http://xmltwig.com/article/ways_to_rome/ways_to_rome.html And now I have learned that it is easy to convert callback-based code to "blocking" code. -- Thanks for this. As I said, it's all about informed choices, I will let everybody (who considers using XML::Reader) know about these choices. Regards, Klaus