I'm breaking my head about this one for 2 days now, so I hope someone can help a bit.
I need the data from an XML, which I get from a website. The code returns a nice list, but missing the time array (array from an array). Here is my code :
<?php
$url="http://publications.elia.be/Publications/Publications/WindForecasting.v1.svc/GetForecastGraphDataXml?beginDate=2015-05-13&endDate=2015-05-18&isOffshore=&isEliaConnected=";
echo $url;
$sxml = Simplexml_load_file($url);
var_dump($sxml);
foreach ($sxml ->ForecastGraphItems ->WindForecastingGraphItem as $type){
echo 'FC ';
echo $type ->Forecast."<br>";
echo 'LF ';
echo $type ->LoadFactor."<br>";
echo 'DT ';
echo $type ->Time[0]->DateTime;
echo "<br>";
echo 'BID ';
echo $type ->Bid."<br>";
echo 'RA ';
echo $type ->RunningAverage."<br>";
echo "<br>";
}
?>
The XML format I get when I just manualy open the website looks like the code below, or check the Original website : http://publications.elia.be/Publications/Publications/WindForecasting.v1.svc/GetForecastGraphDataXml?beginDate=2015-05-13&endDate=2015-05-18&isOffshore=&isEliaConnected=
<?xml version="1.0" encoding="UTF-8"?>
<WindForecastingGraphDataResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Elia.PublicationService.DomainInterface.WindForecasting.v1">
<ErrorMessage i:nil="true"/>
<ForecastGraphItems>
<WindForecastingGraphItem>
<Bid>No</Bid>
<Forecast>571.45</Forecast>
<LoadFactor>0.32</LoadFactor>
<RunningAverage>585.59</RunningAverage>
<Time xmlns:a="http://schemas.datacontract.org/2004/07/System">
<a:DateTime>2015-05-12T22:00:00Z</a:DateTime>
<a:OffsetMinutes>120</a:OffsetMinutes>
</Time>
</WindForecastingGraphItem>
<WindForecastingGraphItem>
<Bid>No</Bid>
<Forecast>562.95</Forecast>
<LoadFactor>0.32</LoadFactor>
<RunningAverage>578.47</RunningAverage>
<Time xmlns:a="http://schemas.datacontract.org/2004/07/System">
<a:DateTime>2015-05-12T22:15:00Z</a:DateTime>
<a:OffsetMinutes>120</a:OffsetMinutes>
</Time>
Now, when I var_dump($sxml)
, or if I try to get it, the sub-array for TIME dropped out... (see below).
I also tried foreach ($sxml ->ForecastGraphItems ->WindForecastingGraphItem -> Time as $time){ ...
, which worked, but returned empty.
Anyone can help why the 'time' array is empty ?
Below the echo for var_dump
:
http://publications.elia.be/Publications/Publications/WindForecasting.v1.svc/GetForecastGraphDataXml?beginDate=2015-05-13&endDate=2015-05-18&isOffshore=&isEliaConnected=object(SimpleXMLElement)#1 (2) { ["ErrorMessage"]=> object(SimpleXMLElement)#2 (0) { } ["ForecastGraphItems"]=> object(SimpleXMLElement)#3 (1) { ["WindForecastingGraphItem"]=> array(481) { [0]=> object(SimpleXMLElement)#4 (5) { ["Bid"]=> string(2) "No" ["Forecast"]=> string(6) "571.45" ["LoadFactor"]=> string(4) "0.32" ["RunningAverage"]=> string(6) "585.59" ["Time"]=> object(SimpleXMLElement)#485 (0) { } } [1]=> object(SimpleXMLElement)#5 (5) { ["Bid"]=> string(2) "No" ["Forecast"]=> string(6) "562.95" ["LoadFactor"]=> string(4) "0.32" ["RunningAverage"]=> string(6) "578.47" ["Time"]=> object(SimpleXMLElement)#485 (0) { } }