Thanks for you attention! You are right, I gave you too little information to help solving my problem. But at that time my handlers were absolutely "crude" and could not give the helpful information. I solved this problem. My handlers are below.
sub start_document { my $self = shift; $self->{lists} = []; $self->{curlist} = $self->{tree} = []; } # # sub start_element { my $self = shift; my $element = shift; my $name = $element->{Name}; $self->{elem_name} = $element->{Name}; my $id; my $var; if ($element->{Attributes}) { $id = $element->{Attributes}->{'{}id'}->{Value}; $var = $element->{Attributes}->{'{}var'}->{Value}; } if ($name eq 'part') { my $newlist = [ {id=>$id, var=>$var} ]; push @{ $self->{lists} }, $self->{curlist}; if ($is_parent) { push @{$self->{curlist}[0]{childs}}, @{$newlist}; } else { push @{ $self->{curlist} }, @{$newlist}; } $self->{curlist} = $newlist; } $is_parent++ if $element->{Name} eq 'part'; } # # sub end_element { my $self = shift; my $element = shift; my $name = $element->{Name}; # Save template name; if ($name eq 'template') { $self->{template} = $self->{char}; } if ($name eq 'part') { $self->{curlist} = pop @{ $self->{lists} }; $is_parent--; } } # # sub characters { my $self = shift; my $chars = shift; my $text = $chars->{Data}; my $clist = $self->{curlist}; $self->{char} = codes2chars($text); } # # sub end_document { my $self = shift; delete ($self->{curlist}); delete ($self->{lists}); my $tree = $self->{tree}; delete ($self->{tree}); $struct->{$self->{menu_name}}->{parts} = $tree; $struct->{$self->{menu_name}}->{template} = $self->{template}; }

In reply to Re^4: Building simple tree from XML by shady
in thread Building simple tree from XML by shady

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.