我被迫使用运行PHP 4的服务器,服务器上的XML服务是DomXML。我的问题是如何使用DomXML访问以下XML文档的特定元素和属性?我尝试了以下操作,没有返回任何结果。任何帮助表示赞赏...
if (!$xml = domxml_open_file($pathToXMLdoc)) {
//the above requires absolube path
exit("Could not access the XML source.");
}
$root = $xml->document_element();
echo($root->current_conditions->conditions['data'] . "<br>");
//XML FILE BELOW
<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>