0
快速問題:我正在使用PHP的SimpleXML對象來解析XML文件。對於我來說,我無法弄清楚如何訪問特定的元素。我的問題是我的PHP看起來像訪問包含在「data」屬性中的節點和信息?我不想遍歷整個文檔,我只想要來自節點的特定信息。我嘗試了以下運氣:使用SimpleXML/PHP從XML訪問元素/屬性
$ xml = simplexml_load_file(「myXML.xml」); echo $ xml-> weather [0] - > forecast_information-> city-> attributes() - > data。 「
」;
在此先感謝。
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_information>
<city data="Carlsbad, CA"/>
<postal_code data="92009"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2012-03-29"/>
<current_date_time data="2012-03-29 11:52:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Partly Cloudy"/>
<temp_f data="62"/>
<temp_c data="17"/>
<humidity data="Humidity: 65%"/>
<icon data="/ig/images/weather/partly_cloudy.gif"/>
<wind_condition data="Wind: SW at 4 mph"/>
</current_conditions>
</weather>
</xml_api_reply>
石溪,工作就像一個魅力。感謝您的幫助,非常感謝!祝你週末愉快... – 2012-03-29 14:09:51
@Mark Johns II:沒問題。當你不知道如何獲取價值觀時,我知道它非常重要。如果現在解決了,也許你可以接受它作爲正確的答案。 – Stony 2012-03-29 14:48:43