title: Get node value using XML::XPath module in Perl
body: <p>I m using the code below to get value of node from a XML file:</p>
  
  <pre><code>use XML::XPath;
  use XML::XPath::XMLParser;
  
  my $pt1 = XML::XPath-&gt;new(filename =&gt; 'test1.xml');
  
  my $nodeset = $pt1-&gt;find('/file1/table/tname'); 
  
  foreach my $node ($nodeset-&gt;get_nodelist) 
  {
     print $node-&gt;getNodeValue."\n";
  }
  </code></pre>
  
  <p><strong>The content of 'test1.xml' is as below:</strong></p>
  
  <pre><code>&lt;file1&gt;
      &lt;table&gt;
          &lt;tname&gt;_sys_ident&lt;/tname&gt;
          &lt;ttype&gt;regular&lt;/ttype&gt;
          &lt;col&gt;
              &lt;name&gt;_sys_ident_asp&lt;/name&gt;
              &lt;type&gt;varchar(16)&lt;/type&gt;
              &lt;fkey&gt;_sys_asp&lt;/fkey&gt;
              &lt;attr&gt;PRIMARY KEY&lt;/attr&gt;
          &lt;/col&gt;
      &lt;/table&gt;
  &lt;/file1&gt;
  </code></pre>
  
  <p>I want to print the value of <strong>tname</strong>(i.e. <strong>_sys_ident</strong>).
  But the above code in not printing anything. </p>
  
  <p>If I use the following inside for loop:</p>
  
  <pre><code>print XML::XPath::XMLParser::as_string($node);
  </code></pre>
  
  <p>then, it gives following output:</p>
  
  <pre><code>&lt;tname&gt;_sys_ident_asp&lt;/tname&gt;
  </code></pre>
  
  <p>I don't want this complete node name and value string. <strong>I just want node value.</strong>
  This is the first time I am trying XML and XPath. Please tell me what I am doing wrong.</p>