Im trying to parse XML in PHP, but I am having problems with it.
So the XML looks like this (simplified)
<weatherdata>
<forecast>
<tabular>
<time from="2015-09-25T20:00:00" to="2015-09-25T23:00:00" period="3">
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
</time>
<time from="2015-09-25T23:00:00" to="2015-09-26T05:00:00" period="0">
<symbol number="9" numberEx="46" name="Light rain" var="46" />
</time>
.....
I was able to load all the time->from values like this:
foreach($xml->forecast->tabular as $forecastItem){
$attr = $forecastItem->attributes();
$froms[] = $attr['from'];
}
But then I tried to load the name attribute of the symbol like this:
foreach($xml->forecast->tabular as $forecastItem){
$attr = $forecastItem->attributes();
$froms[] = $attr['from'];
$attr2 = $forecastItem->symbol->attributes();
$names[] = $attr2['name'];
}
and it shows me an error that main() node does not exist. Basically what I would like to do is load all the names into an array, just like the froms.