title: XML DOMDocument PHP - Get node where attribute value
body: <p><strong>Purpose :</strong> </p>
  
  <p>Create a method to retrieve a nested element with a specific "id".</p>
  
  <p><strong>What I have tried :</strong> </p>
  
  <ul>
  <li>Retrieve the code with x path expressions via DOMXpath class query method. Every time an empty node list was returned</li>
  <li><ul>
  <li>'/row[@id=' . $id . ']'</li>
  </ul></li>
  <li><ul>
  <li>'//table/row[@id=' . $id . ']'</li>
  </ul></li>
  <li><ul>
  <li>'/<em>/</em>[@id=' . $id . ']'</li>
  </ul></li>
  <li>Tried with DOMDocument::getElementById and i set the DOMDocument::$validateOnParse right after instantiating the DOMDocument class. This also returns an empty node list.</li>
  </ul>
  
  <p><strong>Example XML:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;table&gt;
    &lt;row id="1"&gt;
      &lt;job&gt;construction&lt;/job&gt;
      &lt;age&gt;34&lt;/age&gt;
      &lt;name&gt;bob&lt;/name&gt;
    &lt;/row&gt;
    &lt;row id="2"&gt;
      &lt;job&gt;construction&lt;/job&gt;
      &lt;age&gt;34&lt;/age&gt;
      &lt;name&gt;bob&lt;/name&gt;
    &lt;/row&gt;
    &lt;row id="3"&gt;
      &lt;job&gt;construction&lt;/job&gt;
      &lt;age&gt;34&lt;/age&gt;
      &lt;name&gt;bob&lt;/name&gt;
    &lt;/row&gt;
    &lt;row id="4"&gt;
      &lt;job&gt;construction&lt;/job&gt;
      &lt;age&gt;34&lt;/age&gt;
      &lt;name&gt;bob&lt;/name&gt;
    &lt;/row&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>Php code :</strong> </p>
  
  <pre><code>Class SimpleORM{
  
      ...
  
      public function find($id)
      {
          settype($id, "int");
          $xpath = new DOMXPath($this-&gt;_dom);
          $expression = '/row[@id=' . $id . ']';
          return $xpath-&gt;query($expression);
      }
  
  }
  </code></pre>
  
  <p>The fUll Php code can be read here -> <a href="https://github.com/Danoon/SimpleORM/blob/master/SimpleORM.php" rel="nofollow">https://github.com/Danoon/SimpleORM/blob/master/SimpleORM.php</a></p>
  
  <p><strong>Question :</strong> </p>
  
  <p>Why is the proper element/node not returned and how can i achieve this?</p>
  
  <p><strong>Calling the find function</strong></p>
  
  <pre><code>$users = new SimpleORM("users");
  $result = $users-&gt;find(1);
  </code></pre>