title: Perl script to parse XML using XML::LibXML;
body: <p>I think this is a very simple issue, but I cannot figure it out despite many searches.</p>
  
  <p>I am trying to parse the following XML to print something similar to TAG=VALUE, so that I can write this to a CSV file. The problem is the tags are not always the same for each sample. I cannot seem to figure out how to get the actual tag names. Any help appreciated!!!</p>
  
  <p>XML File -</p>
  
  <pre><code>&lt;Statistics&gt;
    &lt;Stats&gt;
      &lt;Sample&gt;
          &lt;Name&gt;System1&lt;/Name&gt;
          &lt;Type&gt;IBM&lt;/Type&gt;
          &lt;Memory&gt;2GB&lt;/Memory&gt;
          &lt;StartTime&gt;2012-04-26T14:30:01Z&lt;/StartTime&gt;
          &lt;EndTime&gt;2012-04-26T14:45:01Z&lt;/EndTime&gt;
      &lt;/Sample&gt;
  
      &lt;Sample&gt;
          &lt;Name&gt;System2&lt;/Name&gt;
          &lt;Type&gt;Intel&lt;/Type&gt;
          &lt;Disks&gt;2&lt;/Disks&gt;
          &lt;StartTime&gt;2012-04-26T15:30:01Z&lt;/StartTime&gt;
          &lt;EndTime&gt;2012-04-26T15:45:01Z&lt;/EndTime&gt;
          &lt;Video&gt;1&lt;/Video&gt;
      &lt;/Sample&gt;
    &lt;/Stats&gt;
  &lt;/Statistics&gt;
  </code></pre>
  
  <p>Script -</p>
  
  <pre><code>#!/usr/bin/perl
  use XML::LibXML;
  
  $filename = "data.xml";
  
  my $parser = XML::LibXML-&gt;new();
  my $xmldoc = $parser-&gt;parse_file($filename);
  
  for my $sample ($xmldoc-&gt;findnodes('/Statistics/Stats/Sample')) {
  
  print $sample-&gt;nodeName(), ": ", $sample-&gt;textContent(), "\n";
  
  }
  </code></pre>