title: Get Xpath parent node with DOMDocument PHP?
body: <p>I need to get the parent of a particular node in php.
  I'm using DOMDocument and XPath.
  My XML is this:</p>
  <pre><code>&lt;ProdCategories&gt;
  &lt;ProdCategory&gt;
  
      &lt;Id&gt;138&lt;/Id&gt;
  
      &lt;Name&gt;Parent Category&lt;/Name&gt;
  
      &lt;SubCategories&gt;
  
          &lt;ProdCategory&gt;
  
              &lt;Id&gt;141&lt;/Id&gt;
  
              &lt;Name&gt;Category child&lt;/Name&gt;
  
          &lt;/ProdCategory&gt;
     &lt;/SubCategories&gt;
  &lt;/ProdCategory&gt;
  &lt;/ProdCategories&gt;
  </code></pre>
  <p>The php code:</p>
  <pre><code>$dom = new DOMDocument();
  $dom-&gt;load(&quot;ProdCategories_small.xml&quot;);
  $xpath = new DOMXPath($dom);
  $nodes = $xpath-&gt;query('//ProdCategory/Id[.=&quot;141&quot;]/parent::*')-&gt;item(0);
  print_r($nodes); 
  </code></pre>
  <p>The print is:</p>
  <blockquote>
  <pre><code> DOMElement Object ( 
   [tagName] =&gt; ProdCategory [schemaTypeInfo] =&gt; [nodeName] =&gt; ProdCategory [nodeValue] =&gt; 141 Category child [nodeType] =&gt; 1 [parentNode] =&gt; (object value omitted) [childNodes] =&gt; (object value omitted) [firstChild] =&gt; (object value omitted) [lastChild] =&gt; (object value omitted) [previousSibling] =&gt; (object value omitted)
  </code></pre>
  </blockquote>
  <p>The <strong><code>[parentNode]</code></strong> is <strong><code>(object value omitted)</code></strong>, why? I would get </p>
  <pre><code>    &lt;Id&gt;138&lt;/Id&gt;
  
      &lt;Name&gt;Parent Category&lt;/Name&gt;`
  </code></pre>