I have a xml fragment as such:
<top_level>
   <name>test case</name>
   <junk>just some more tags</junk>
   <sub_level_1>
        <element name="attr1">
              <value format="inches">121</value>
              <modifier>add</modifier>
        </element>
        <element name="attr2">
              <value format="yards">1.5</value>
              <modifier>sub</modifier>
        </element>
   </sub_level_1>
</top_level>
In using XML::DT I can format it such that I get each value in the hash, but I am looking to reformat the hash via XML::DT.
%handler = ( -default => sub{$c}, 
            -type => {name => 'MAP',
                      junk => 'MAP',
                      sub_level_1 => 'SEQ', 
                      element => 'MAP'
                     });

returns
 $VAR = { name => 'test case',
          junk => 'just some more tags',
          sub_level_1 => start_array # submit form rejects bracket
                             {value => '121', modifier => 'add'},
                             {value => '1.5', modifier => 'sub'}
                            end_array}
what I would like to return is: (notice attributes are used as hash index)
                         
 $VAR = { name => 'test case',
          junk => 'just some more tags',
          sub_level_1 => { attr1 => {value => '121', modifier => 'add'},
                           attr2 => {value => '1.5', modifier => 'sub'}}}
Now I know this has to do with the declaring a sub function but I am having difficult with the pointers.
%handler = ( -default => sub{$c}, 
            -type => {name => 'MAP',
                      junk => 'MAP',
                      element => 'MAP'
                     },
            sub_level_1 => sub { split('\n', $c) } 
              # returns list of pointers
              # but need hash indexed by attribute name
              # This is where I need HELP - Please
           );

Thanks Joe

In reply to XML::DT and hashes/pointers 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.