I need to parse the “name” and “version” attributes from all of the “<mod>” tag entries.
Thanks to this page I was only able to parse the first “<mod>” tag from the xml.
I’m no programmer, so I have no clue how to go on.
This is my xml file.
These are my testing php files.
$xmlfile = simplexml_load_file("packa.xml");
foreach ($xmlfile->children() as $mods) {
echo $mods->mod['name']."</br>";
echo $mods->mod['version'];
}
had this output.
</br></br>Just Enough Items</br>4.15.0.293
And
foreach ($xmlfile->children() as $mods) {
echo $mods->mod['name']."
</br>".$mods->mod['version'];
}
had this output
</br>
</br>Just Enough Items
</br>4.15.0.293
2
Answers
You can try something along these lines, using xpath:
Output:
etc.
You are using the wrong level in the XML in the
foreach()
loop, this is only looping over the<mods>
elements – and there is only 1. You need to specify that you want to loop over the<mod>
elements and then just access the attributes as you already do…