I am new to PHP and XML.
Can somebody tell me how can I get the values of a sub element or child node of a an xml element?
index.php
$domdoc = new DOMDocument();
$domdoc->load('actionstars.xml');
foreach ($domdoc->getElementsByTagName("actionstar") as $star) {
echo $star->item(0)->nodeValue; // displays the <id> element
echo $star->item(1)->nodeValue; // displays the <name> element
echo "<br />";
}
actionstars.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<actionstars>
<actionstar>
<id>1</id>
<name>Jean Claude Van Damme</name>
</actionstar>
<actionstar>
<id>2</id>
<name>Scott Adkins</name>
</actionstar>
<actionstar>
<id>3</id>
<name>Dolph Ludgren</name>
</actionstar>
<actionstar>
<id>4</id>
<name>Michael Jai White</name>
</actionstar>
<actionstar>
<id>5</id>
<name>Michael Worth</name>
</actionstar>
</actionstars>
Pls help…
If you can guarantee their order, you can use
childNodesand the offset, otherwise…