I recommend XML::Twig:
use strict; use warnings; use XML::Twig; use Data::Dumper; my $xfile = <<EOF; <?xml version="1.0" encoding="utf-8"?> <install type="module" version="1.0.0"> <name>TEST</name> <notebook_tabs> <tab index="1">Create <button internal_name="test1" parent="-1" text="button 1" x_coordinate="5" y_coordinate="5" x_size="-1" y_size="-1" evt_1="EVT_BUTTON" evt_1_function="testclick" /> <button internal_name="test2" parent="-1" text="button 2" x_coordinate="50" y_coordinate="50" x_size="-1" y_size="-1" evt_1="EVT_BUTTON" evt_1_function="testclick2" /> </tab> <tab index="2">Assign</tab> </notebook_tabs> </install> EOF my $t= new XML::Twig(); $t->parse($xfile); my $install = $t->root(); my $note_tabs = $install->first_child('notebook_tabs'); my @tabs = $note_tabs->children('tab'); for my $tab (@tabs) { print "\nTab ", $tab->att('index'), "\n"; my @buttons = $tab->children('button'); print "number of buttons = ", scalar @buttons, "\n"; for my $button (@buttons) { my @params = $button->atts(); print Dumper(\@params); } }

Prints:

Tab 1 number of buttons = 2 $VAR1 = [ { 'parent' => '-1', 'y_coordinate' => '5', 'x_coordinate' => '5', 'evt_1_function' => 'testclick', 'x_size' => '-1', 'evt_1' => 'EVT_BUTTON', 'internal_name' => 'test1', 'text' => 'button 1', 'y_size' => '-1' } ]; $VAR1 = [ { 'parent' => '-1', 'y_coordinate' => '50', 'x_coordinate' => '50', 'evt_1_function' => 'testclick2', 'x_size' => '-1', 'evt_1' => 'EVT_BUTTON', 'internal_name' => 'test2', 'text' => 'button 2', 'y_size' => '-1' } ]; Tab 2 number of buttons = 0

In reply to Re: XML Parsing questions and recommendations? by toolic
in thread XML Parsing questions and recommendations? by Anonymous Monk

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.