1
我使用PHP foreach循環解析下面的數據,我需要從measuredValue索引2和索引3中提取數據,但是我不確定如何執行此操作。下面的代碼顯示了我用來從XML文件中提取數據的內容。我需要在'索引1'中進行溫度工作,但我無法弄清楚如何進入下一個'索引'部分。PHP XML解析,多重'索引'問題
foreach ($weather_array->payloadPublication->siteMeasurements as $roaddt){
echo ("
<tr>
<td> " .$roaddt->measurementSiteReference. "</td>
<td> " .$roaddt->measurementTimeDefault. "</td>
<td> " .$roaddt->measuredValue->basicDataValue->temperature->airTemperature. "</td>
<td> " .$roaddt->measuredValue->basicDataValue->wind->windDirectionCompass. "</td>
</tr> ");
}
echo "</table>";
下面的代碼是什麼,我想從拉部分:
<siteMeasurements>
<measurementSiteReference>NRA10810</measurementSiteReference>
<measurementTimeDefault>2017-02-28T15:50:00+00:00</measurementTimeDefault>
<measuredValue index="1">
<basicDataValue xsi:type="TemperatureInformation">
<period>3600</period>
<temperature>...</temperature>
</basicDataValue>
</measuredValue>
<measuredValue index="2">
<basicDataValue xsi:type="PrecipitationInformation">
<period>3600</period>
<precipitationDetail></precipitationDetail>
</basicDataValue>
</measuredValue>
<measuredValue index="3">
<basicDataValue xsi:type="WindInformation">
<period>3600</period>
<wind>
<maximumWindSpeed>45</maximumWindSpeed>
<windDirectionBearing>302</windDirectionBearing>
<windDirectionCompass>westNorthWest</windDirectionCompass>
<windSpeed>27.4</windSpeed>
</wind>
</basicDataValue>
</measuredValue>
如何讀取XML(即如何分配$ weather_array)? –