arunvelusamy has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

We are in maintaining a existing application which uses XML::Simple to parse xml data. As the input xml data size has grown big in size, we are looking for some module to process data in batches. ie., the current xml file size is 50MB. We want to process data not more than 5 or 10MB at a time.

A outline of what the application does,
* receives XML content via HTTPResponse.
* Converts it into hash using XML::Simple
* Calls the appropriate method, to process the data based on first tag. And the hashed xml data is passed to that method. ie.,

if xml data is <tag1 ..> .... </tag1> process1($hashed_xml_data) if xml data is <tag2 ..> ... </tag2> process2($hashed_xml_data)
My friend suggests me XML::Twig. I know only a little about XML::TWig and as far as i know, we need to define every tags and it would give me quite a lot of code changes. Can any one help us with example of how this can be worked out.

Thanks in advance,

ArunV

Replies are listed 'Best First'.
Re: XML::Simple to XML::Twig
by GrandFather (Saint) on Jul 16, 2007 at 23:58 UTC

    Something like:

    use strict; use warnings; use XML::Twig; my $xml = <<XML; <root> <tag1> tag 1 data </tag1> <tag2> tag 2 data </tag2> </root> XML my $root = XML::Twig->new ( twig_handlers => { tag1 => \&process1, tag2 => \&process2, } ); $root->parse ($xml); sub process1 { print "Process1: " . $_->children_text () . "\n"; } sub process2 { print "Process2: " . $_->children_text () . "\n"; }

    Prints:

    Process1: tag 1 data Process2: tag 2 data

    DWIM is Perl's answer to Gödel