title: php simplexml with unique values
body: <p>I have an xml file and using simplexml :</p>
  
  <pre><code>   $xml = simplexml_load_file('feed.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
  
     foreach($xml-&gt;item as $products)
       {
       $name =  (string)trim($products-&gt;name) ;
       $weight = (string)$products-&gt;weight;
  
       .....and so on...
  </code></pre>
  
  <p>The xml feed is as follows:</p>
  
  <pre><code>   &lt;?xml version="1.0"?&gt;
      &lt;root&gt;
      &lt;update_time&gt;2014-06-09&lt;/update_time&gt;
  
      &lt;item&gt;
      &lt;name&gt;Product 1&lt;/name&gt;
      &lt;weight&gt;0.3000&lt;/weight&gt;
      &lt;Price&gt;31.4400&lt;/Price&gt;
      &lt;/item&gt;
  
     &lt;item&gt;
      &lt;name&gt;Product 2&lt;/name&gt;
      &lt;weight&gt;0.2000&lt;/weight&gt;
      &lt;Price&gt;32.4400&lt;/Price&gt;
      &lt;/item&gt;
  
    &lt;item&gt; //duplicate
      &lt;name&gt;Product 1&lt;/name&gt;
     &lt;weight&gt;0.1000&lt;/weight&gt;
     &lt;Price&gt;22.4400&lt;/Price&gt;
     &lt;/item&gt;
  
     &lt;/root&gt;      
  </code></pre>
  
  <p>The name value had duplicates and i need only values without duplicates. I need to <strong>eliminate the whole item node (all children) with duplicate name child.</strong></p>
  
  <p>I have read that this can be done with xpath. How can i do it in the above code?? Can xpath be used inside foreach loop? pretty confused on how to incorporate this in my code above.</p>
  
  <p>Help requested..</p>