Consider the following XML document:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product code="WERGTR">
</product>
<product code="HERGGFH">
</product>
<product code="NYTERBT">
</product>
<product code="NUYRTHT">
</product>
<misc>
<copyrightHTML>Somo stuff</copyrightHTML>
<categoryLink name="Attr1">http://www.example.com/val1</categoryLink>
<categoryLink name="Attr2">http://www.example.com/val2</categoryLink>
<categoryLink name="Attr3">http://www.example.com/val3</categoryLink>
<categoryLink name="Attr4">http://www.example.com/val4</categoryLink>
</misc>
</catalog>
How can I echo each <categoryLink>
element? Displaying its value and attribute name
value?
I've tried using
$pricesDatabase = "http://www.example.com/database.xml";
$xml = simplexml_load_file($pricesDatabase) or die("Couldn't create database.xml");
foreach($xml->children() as $links) {
echo $links->categoryLink['name'];
echo "<br>";
}
But doesn't work, it simply shows nothing.
The result I'm looking for could be as below:
$key . ": value: " . $value . ", name: " . $nameValue
So...
[0]: value: http://www.example.com/val1, name: Attr1
[1]: value: http://www.example.com/val2, name: Attr2
[2]: value: http://www.example.com/val3, name: Attr3
[3]: value: http://www.example.com/val4, name: Attr4