title: Doing XPath using Perl
body: <p>I am coding with Perl on a Window 7 machine. I am able to extract data from the XML using the XPath code below</p>
  
  <pre><code>use strict;
  use warning;
  
  use XML::LibXML;
  
  my $parser = XML::LibXML-&gt;new();
          my $doc    = $parser-&gt;parse_file($newfile);
          my $query  = "/tradenet/message/header/unique_ref_no/date/text( )";
          my($node)   = $doc-&gt;findnodes($query);
          $node-&gt;setData("$file_seq_number");  
  </code></pre>
  
  <p>However, when i use the same code on a different XML, the xpath from the second document looks as below:</p>
  
  <pre><code>/TradenetResponse/OutboundMessage/out:OutwardPermit/out:Declaration/out:Header/cac:UniqueReferenceNumber/cbc:SequenceNumeric
  </code></pre>
  
  <p>Together with the Perl code, this is what the extraction code looks like:</p>
  
  <pre><code>my $parser = XML::LibXML-&gt;new();
      my $doc    = $parser-&gt;parse_file($newfile);
      my $query  = "/TradenetResponse/OutboundMessage/out:OutwardPermit/out:Declaration/out:Header/cac:UniqueReferenceNumber/cbc:SequenceNumeric/text( )";
      my($node)   = $doc-&gt;findnodes($query);
      $node-&gt;setData("$file_seq_number");
  </code></pre>
  
  <p>Using the second code, I am unable to retrieve the data from the second XML. I receive this error "Can't call method "setData"on an undefined value at Perl.pl line 5".</p>
  
  <p>Does the ":" character in the second XPATH address affecting the code? </p>