現在我已經打破了這個問題兩天了,所以我希望有人能幫上忙。來自URL的XML multidimentional array php
我需要從網站獲得的XML數據。該代碼返回一個不錯的列表,但缺少時間數組(數組中的數組)。 這裏是我的代碼:
<?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>";
}
?>
的XML格式,我得到的時候我只是manualy打開該網站看起來像下面的代碼,或檢查原網站: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>
現在,當我var_dump($sxml)
,或者如果我嘗試獲取它,則TIME的子數組將被刪除...(請參見下文)。 我也試過foreach ($sxml ->ForecastGraphItems ->WindForecastingGraphItem -> Time as $time){ ...
,它工作,但返回空。
任何人都可以幫助爲什麼'時間'數組是空的?
下面回波爲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」] =>對象(的SimpleXMLElement)#2(0){} [ 「ForecastGraphItems」] =>對象( SimpleXMLElement#3(1){「WindForecastingGraphItem」] =>數組(481){[0] => object(SimpleXMLElement)#4(5){[「Bid」] => string(2) 「 [」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)「否」 [「Forecast」] => string(6)「562.95」[「LoadFactor」] => string(4 ) 「0.32」 [ 「RunningAverage」] =>串(6) 「578.47」[ 「時間」] => 對象(的SimpleXMLElement)#485(0){}}
這是因爲命名空間'a'在'' –
michi