I am a 2 week old Perl user and I am trying to parse a 300 mb nested XML file. So please excuse my lack of knowledge. The file follows a similar format as below

<?xml version="1.0" encoding="UTF-8"?> <APP:Report xmlns:APP="WWW" xmlns:xsi="WWW" xsi:schemaLocation="WWW"> <library> <Cat1> <Book>The book of pages</Book> <Snap></Snap> <Line1>The Beginning</Line1> <Line2>We ceased to exist</Line2> <Line3>Accept it</Line3> <Line4>Now we live</Line4> <Line5>We reject it</Line5> <Rating> <C1> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C1> <C2> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C2> <C3> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C3> </Rating> </Cat1> <Author>Sally</Author> <Publisher>Penguin</Publisher> <Cat2> <Book>The song</Book> <Snap></Snap> <Line1>This is how we do it</Line1> <Line2>I hope this works</Line2> <Line3>Please do</Line3> <Line4>Begging you</Line4> <Line5>Bye</Line5> <Rating> <C1> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C1> <C2> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C2> <C3> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>3.5</X> <Y>13.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> <elt> <X>10.5</X> <Y>11.4</Y> </elt> </C3> </Rating> </Cat2> <Author>Justin</Author> <Publisher>Victoria</Publisher> </library> </APP:Report>

I want to be able to able to display Book, Snap, Line1, Line2, line3, Line4, line5, C1, C2 and C3 in different columns of the first row, Author in row 2 and Publisher in row 3. This is just a sample of the big file that I have. I do not want to access a specific child to display. I want to be able to display all its descendants. Currently it is printing all my data row 1 column 1. My code snippet is enclosed below. What would be the best way to do this? I would gratefully appreciate any advice. Thank you!

my $twig= new XML::Twig(); $twig->parsefile( $_); # build the twig foreach my $elt ($twig->root->children) { print $fout1 $elt->text."\n"; }
I have edited my question. Suppose I have different types of nested children within each book. How do I display and access these nested children? I want to display it as
The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C1.X|X 6 times The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C1.Y|X 6 times The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C2.X|X 6 times The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C2.Y|X 6 times The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C3.X|X 6 times The book of pages|Snap|Line1|Line2|Line3|Line4|Line5|C3.Y|X 6 times . . . . . The song|Snap|Line1|Line2|Line3|Line4|Line5|C2.X|X 6 The song|Snap|Line1|Line2|Line3|Line4|Line5|C2.Y|X 6

In reply to how to display descendants in XML with Perl's XML::Twig 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.