title: Extracting a multiple level XML using Perl
body: <p>I'm trying to extract data from an XML file. </p>
  
  <p>The format of the XML is as follows:</p>
  
  <pre><code>&lt;notifications&gt;
  &lt;notification name="ccmSmtp" oid="1.3.6.1" status="current"&gt;
    &lt;objects&gt;
      &lt;object module="callhome" name="ccmSmtp"/&gt;
    &lt;/objects&gt;
    &lt;description&gt;
       This is a description
    &lt;/description&gt;
  &lt;/notification&gt;
  &lt;notification name="ccmAlertGroup" oid="1.3.6.1" status="current"&gt;
    &lt;objects&gt;
      &lt;object module="callhome" name="callHome"/&gt;
    &lt;/objects&gt;
    &lt;description&gt;
         This is a description
    &lt;/description&gt;
  &lt;/notification&gt;
  &lt;notification name="ccmAlert" oid="1.3.6.1" status="current"&gt;
    &lt;objects&gt;
      &lt;object module="callhome" name="callHome"/&gt;
    &lt;/objects&gt;
    &lt;description&gt;
      This is a description
    &lt;/description&gt;
  &lt;/notification&gt;
  &lt;notification name="ccmSmtp" oid="1.3.6.1" status="current"&gt;
    &lt;objects&gt;
    &lt;/objects&gt;
    &lt;description&gt;
        This is a description
    &lt;/description&gt;
  &lt;/notification&gt;
  &lt;/notifications&gt;
  </code></pre>
  
  <p>I have written the following code to extract the notifications node from example.xml file.</p>
  
  <pre><code>#!/usr/bin/perl
  
  use XML::Simple;
  use Data::Dumper;
  
  $xml = new XML::Simple;
  
  $data = $xml-&gt;XMLin("example.xml",KeyAttr =&gt; {
    notifications =&gt; notification =&gt; 'name'
  });
  
  $notification = $data-&gt;{notifications};
  
  print Dumper($notification);
  </code></pre>
  
  <p>When I run the above Perl file I get the following output:</p>
  
  <pre><code>$VAR1 = {
    'notification' =&gt; [
        {
          'objects' =&gt; {
            'object' =&gt; {
              'name' =&gt; 'ccmSmtp',
              'module' =&gt; 'callhome'
            }
          },
          'status' =&gt; 'current',
          'oid' =&gt; '1.3.6.',
          'name' =&gt; 'ccmSmtp',
          'description' =&gt; ' This is a mib '
        },
        {
          'objects' =&gt; {
            'object' =&gt; {
              'name' =&gt; 'callHome',
              'module' =&gt; 'module'
            }
          },
          'status' =&gt; 'current',
          'oid' =&gt; '1.3.6.1.4',
          'name' =&gt; 'ccmAlert',
          'description' =&gt; 'This is a description'
        },
        {
          'objects' =&gt; {
            'object' =&gt; {
              'name' =&gt; 'callHome',
              'module' =&gt; 'homemib'
            }
          },
          'status' =&gt; 'current',
          'oid' =&gt; '1.3.6.1.4',
          'name' =&gt; 'ccmAlertf',
          'description' =&gt; 'This is a description'
        },
        {
          'objects' =&gt; {},
          'status' =&gt; 'current',
          'oid' =&gt; '1.3.6.1',
          'name' =&gt; 'ccmSmtp',
          'description' =&gt; ' This is an example'
        }
      ]
  };
  </code></pre>
  
  <p>My question is, how can I extract the contents of notification node and store the values in separate variables/array ?</p>