title: parse simplexml based on child value
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6279544/php-xpath-find-element-with-a-value-and-also-get-elements-before-and-after-ele">PHP xpath - find element with a value and also get elements before and after element</a>  </p>
  </blockquote>
  
  
  
  <p>I have the following xml:</p>
  
  <pre><code>&lt;Table&gt;
      &lt;ID&gt;100&lt;/ID&gt;
      &lt;Name&gt;Fridge&lt;/Name&gt;
      &lt;Description&gt;A cool refrigerator&lt;/Description&gt;
  &lt;/Table&gt;
  &lt;Table&gt;
      &lt;ID&gt;100&lt;/ID&gt;
      &lt;Name&gt;Fridge&lt;/Name&gt;
      &lt;Description&gt;Latest Refrigerator&lt;/Description&gt;
  &lt;/Table&gt;
  &lt;Table&gt;
      &lt;ID&gt;200&lt;/ID&gt;
      &lt;Name&gt;Fridge&lt;/Name&gt;
      &lt;Description&gt;Another refrigerator&lt;/Description&gt;
  &lt;/Table&gt;
  </code></pre>
  
  <p>In the example above, I would like to get the child values of Name and Description for the nodes with ID=100. There are around 1000 Table nodes in the xml file.</p>
  
  <p>How can i parse the entire xml and get the Name and Description values for only the nodes with ID equal to 100 ?</p>
  
  <p>So far, i have tried the following code, which could not give what i wanted:</p>
  
  <pre><code>$source = 'Tables.xml';
  $xmlstr = file_get_contents($source);
  $sitemap = new SimpleXMLElement($xmlstr);
  
  $sitemap = new SimpleXMLElement($source,null,true);
  
  foreach($sitemap as $url) {
  
      if($url-&gt;ID == '100')
      {
          echo 'Name: '.(string)$url-&gt;Name.', Description: '.(string)$url-&gt;Description.'&lt;br&gt;';
      }
  }
  </code></pre>