I am currently using XML twig to parse this. I will be more than happy to try other options.

There are other (few) options, but not XML::Simple. Avoid it. I suspect that you unhappiness is due not to XML::Twig but to the shaggy beast XML is, per se.

Anyway i do not understand your expected output format:

d1|d2|Nest1->Nest2->d5->X|Nest1->Nest2->d5->Y|Nest1->Nest2->d6->X|Nest1->Nest2->d6->Y|Nest1->Nest2->Nest3->Nest4->d7->d9->d10->text.

what the above means?

Modifying a little your program (using strict too..)

use strict; #use this! use warnings; use XML::Twig; # use XML::Simple; NOOOO! # $localfile= "Test_1.xml"; used DATA instead my $field = "Nest1"; open my $fout1, '>', "testx.csv" or die "Could not open file!"; my $twig = XML::Twig->new( twig_roots => { $field => 1, 'd1' => 1, 'd2'=> 1, }, twig_handlers => { 'DatatoParse' => \&node, 'DatatoParse//*' => \&node1 } ); $/=''; ## added this $twig->parse(<DATA>); #modified this sub node { my($twig, $el) = @_; $twig->purge; } sub node1{ print $fout1 "\n", if ($_->tag eq "d1"); print $fout1 $_->text, ",", unless ($_->has_children('#EL +T')); print $fout1 "\n", if ($_->tag eq "elt"); } __DATA__ <DatatoParse> <elt> ....

I obtain some output that make some sense and no garbage at all:

#cat testx.csv TV show 1,Heroes,FULL,Page 65,-2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, TV show 2,Prison Break,FULL,Page 65,-2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, TV show 4,Alias,FULL,Page 65,-2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee, -2,-3,5,8,yipppeee,yipppeee,

What is wrong with this? What output you want?

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Parsing a highly nested XML file correctly and efficiently by Discipulus
in thread Parsing a highly nested XML file correctly and efficiently by Ppeoc

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.