title: How to retrieve attributes with XPath and Perl
body: <p>I have the following XML structure:</p>
  
  <pre><code>&lt;RECORD&gt;
  &lt;TYPE ID="check_ping"&gt;
  &lt;HOSTS&gt;
  &lt;HOST H="192.168.0.1" W="50,1%" C="100,1%" /&gt;
  &lt;HOST H="192.168.0.2" W="50,1%" C="70,1%" /&gt;
  &lt;/HOSTS&gt;
  &lt;/TYPE&gt;
  &lt;TYPE ID="check_ssh"&gt;
  &lt;HOSTS&gt;
  &lt;HOST H="192.168.0.3" P="21"/&gt;
  &lt;HOST H="192.168.0.4" P="21"/&gt;
  &lt;HOST H="192.168.0.4" P="21"/&gt;
  &lt;/HOSTS&gt;
  &lt;/TYPE&gt;
  ....
  &lt;/RECORD&gt;
  </code></pre>
  
  <p>I have also a Perl script that is supposed to read that XML, I am using <em>XML::XPath module</em>.</p>
  
  <pre><code>use XML::XPath;
  #.....
  my $xp = XML::XPath-&gt;new(filename =&gt; 'test.xml');
  #RETRIEVE ALL HOSTS WITH CHECK_SSH
  my $querysshh = '/RECORD/TYPE[@ID="check_ssh"]/HOSTS/HOST';
  $nodeset = $xp-&gt;find($querysshh);
  foreach $mynode ($nodeset-&gt;get_nodelist) {
  #HOW DO I RETRIEVE ATTRIBUTES NOW?
  }
  #.....
  </code></pre>
  
  <p>How can I retrieve the attributes of those nodes? For example if I want to read <em>H</em> and <em>P</em> what do I need to do? I looked at the module documentation but I couldnt find any useful method.</p>