I have an xml file and using simplexml :
$xml = simplexml_load_file('feed.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
foreach($xml->item as $products)
{
$name = (string)trim($products->name) ;
$weight = (string)$products->weight;
.....and so on...
The xml feed is as follows:
<?xml version="1.0"?>
<root>
<update_time>2014-06-09</update_time>
<item>
<name>Product 1</name>
<weight>0.3000</weight>
<Price>31.4400</Price>
</item>
<item>
<name>Product 2</name>
<weight>0.2000</weight>
<Price>32.4400</Price>
</item>
<item> //duplicate
<name>Product 1</name>
<weight>0.1000</weight>
<Price>22.4400</Price>
</item>
</root>
The name value had duplicates and i need only values without duplicates. I need to eliminate the whole item node (all children) with duplicate name child.
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.
Help requested..