I am trying to parse an xml file, the parent and children use – instead of _ which I’m used to.
<the-parent>
<the-children>Value</the-children>
</the-parent>
I have been using simplexml_load_file() to parse past xml files and putting it through a foreach() loop to echo everything back out.
$xml = simplexml_load_file($url);
foreach($xml->the-parent as $parent) {
echo $parent->the-children;
}
I keep getting this error Warning: Invalid argument supplied for foreach()
I can’t change the format of the xml file because I am getting it from a 3rd-party. What are my options for parsing this correctly?
You can do something like
$xml->{'the-parent'}.See example #3: http://www.php.net/manual/en/simplexml.examples-basic.php