I’m new to XML and have so far managed to obtain the root node of an XML using this in php…
function xmlRootNode($xmlfile){
$xml = simplexml_load_string(file_get_contents($xmlfile));
$xml = $xml->getName();
echo $xml;
}
And what I now want to do is use that root node to find out the name of its child node.
For example, a file with the below would output ‘food’ as the root using the above function. How would I now use that to return its childs name ‘fruit’?
<food>
<fruit>
<type>apples</type>
</fruit>
</food>
Ultimately what I’m trying to do is find out the child node name of the root node so I can then use it in another function that counts how many there are. Been googling and messing around with different ideas but think I’m missing a simple process somewhere so any ideas would be appreciated.
Try
Additional, the below is redundant,
switch it to