I have a XML data stored in $string
variable in php like this
<DATA>
<STOREITEMS>
<CREATED date="Tue Oct 9 5:30:01 BST 2012">
<CATEGORY id="442" name="Hen And Stag Nights"></CATEGORY>
<CATEGORY id="69" name="Games"></CATEGORY>
<CATEGORY id="252" name="Love Zone"></CATEGORY>
<CATEGORY id="202" name="Spotlight Items"></CATEGORY>
</CREATED>
<CREATED date="Wed Oct 10 5:30:01 BST 2012">
<CATEGORY id="442" name="Hen And Stag Nights"></CATEGORY>
<CATEGORY id="69" name="Games"></CATEGORY>
<CATEGORY id="252" name="Love Zone"></CATEGORY>
<CATEGORY id="202" name="Spotlight Items"></CATEGORY>
</CREATED>
</STOREITEMS>
<DATA>
I need to print date of nodes using php
I have tried the following code
$xml = new SimpleXMLElement($string);
$result = $xml->xpath("//DATA/STOREITEMS");
foreach ($result as $node) {
echo $node->CREATED["date"];
echo "<br>";
}
but it always return only
Tue Oct 9 5:30:01 BST 2012
why its not returning like
Tue Oct 9 5:30:01 BST 2012
Wed Oct 10 5:30:01 BST 2012
How to fix this?