title: How to use XML::LibXML to parse an XML document and build a Perl hash
body: <p>I have XML data that will be like this </p>
  
  <pre><code>&lt;Root&gt;
    &lt;Bag Identifier="1"&gt;
      &lt;Code Amount="0" Code="XA" Conversion="0" Currency="INR" Desc="" Id="1"/&gt;
    &lt;/Bag&gt;
    &lt;Bag Identifier="2"&gt;
      &lt;Code Amount="21" Code="XA" Conversion="0" Currency="INR" Desc="" Id="2"/&gt;
    &lt;/Bag&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>I want to parse this and create a Perl hash as below. The <code>Identifier</code> attribute of each <code>Bag</code> element should be the primary hash key.</p>
  
  <pre><code>'2' =&gt; {
    'Amount' =&gt; "21",
    'Code' =&gt; "XA",
    'Currency' =&gt; "INR",
  }
  '1' =&gt; {
    'Amount' =&gt; "0",
    'Code' =&gt; "XA",
    'Currency' =&gt; "INR",
  }
  </code></pre>
  
  <p>This is my Perl code</p>
  
  <pre><code>my $parser = XML::LibXML-&gt;new();
  my $xml_doc = $parser-&gt;parse_string($response);
  
  my $test_node = $xml_doc-&gt;findnodes('//Bag/');
  print Dumper($test_node);
  
  print $test_node-&gt;find('@Id')-&gt;string_value();
  </code></pre>
  
  <p>How can I create the hash that I have described?</p>