To use XML::LibXML on large files, use the pull parser XML::LibXML::Reader. For example, the following script
#!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; my $reader = 'XML::LibXML::Reader'->new( location => shift ) or die "Can't open file.\n"; while ($reader->read) { if ('product' eq $reader->name) { my $dom = $reader->copyCurrentNode(1); print $dom->findvalue('product_id'), "\n"; for my $attr ($dom->findnodes('attributes/attribute')) { my $groups = $attr->findnodes('group'); for my $group (@$groups) { my $gid = $group->findnodes('id'); my $gname = $group->findnodes('name'); print "\tgroup [ $gid : $gname ]\n"; } my $values = $attr->findnodes('value'); for my $value (@$values) { my $vid = $value->findnodes('id'); my $vval = $value->findnodes('value'); print "\tvalue [ $vid : $vval ]\n"; } } } }

produces the following output:

ABC123 group [ 1507 : Engines ] value [ 301 : Generator ] group [ 1561 : Längd (i mm) ] value [ : 2625 ] group [ 1498 : Year model ] value [ : 01.1994 ] group [ 1518 : Year model (to) ] value [ : 12.1998 ] group [ 12033 : Vehicle equipment ] value [ 12019 : Maybe ] XYZ789 group [ 1507 : Engines ] value [ 301 : Generator ] group [ 1498 : Year model ] value [ : 01.1985 ] group [ 1518 : Year model (to) ] value [ : 12.1992 ]
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re^2: Easy XML-parser that can handle large file? by choroba
in thread Easy XML-parser that can handle large file? by DreamT

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.