title: Extracting one node with LibXML
body: <p>This may be very novice of me, but I am a novice at Perl LibXML (and XPath for that matter). I have this XML doc:</p>
  
  <pre><code>&lt;Tims
      xsi:schemaLocation="http://my.location.com/namespace http://my.location.com/xsd/Tims.xsd"
      xmlns="http://my.location.com/namespace"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
          &lt;Error&gt;Too many entities for operation.  Acceptable limit is 5,000 and 8,609 were passed in.&lt;/Error&gt;
          &lt;Timestamp&gt;2012-07-27T12:06:24-04:00&lt;/Timestamp&gt;
          &lt;ExecutionTime&gt;41.718&lt;/ExecutionTime&gt;
  &lt;/Tims&gt;
  </code></pre>
  
  <p>All I want to do is get the value of <code>&lt;Error&gt;</code>. Thats all. I've tried plenty of approaches, most recently <a href="https://stackoverflow.com/questions/8411684/xmllibxml-replace-element-value">this</a> one. I've read the docs through and through. This is what I currently have in my code:</p>
  
  <pre><code>#!/usr/bin/perl -w
  
  my $xmlString = &lt;&lt;XML;
  &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;Tims
      xsi:schemaLocation="http://my.location.com/namespace http://my.location.com/xsd/Tims.xsd"
      xmlns="http://my.location.com/namespace"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
      &lt;Error&gt;Too many entities for operation.  Acceptable limit is 5,000 and 8,609 were passed in.&lt;/Error&gt;
      &lt;Timestamp&gt;2012-07-27T12:06:24-04:00&lt;/Timestamp&gt;
      &lt;ExecutionTime&gt;41.718&lt;/ExecutionTime&gt;
  &lt;/Tims&gt;
  XML
  
  use XML::LibXML;
  
  my $parser = XML::LibXML-&gt;new();
  my $doc = $parser-&gt;parse_string($xmlString);
  my $root = $doc-&gt;documentElement();
  my $xpc = XML::LibXML::XPathContext-&gt;new($root);
  
  $xpc-&gt;registerNs("x", "http://my.location.com/namespace");
  
  foreach my $node ($xpc-&gt;findnodes('x:Tims/x:Error')) {
          print $node-&gt;toString();
  }
  </code></pre>
  
  <p>Any advice, links, anything is appreciated. Thanks.</p>