[英]Retrieve data from XML string
我正在尝试从以下XML输出中检索数据:
<string xmlns="http://tempuri.org/soap/AustralianTourismWebService">
<?xml version="1.0" encoding="utf-16" ?><atdw_data_results><area area_id="9000672" area_name="Gippsland area" attribute_id_area_type="LOCAL">
<city suburb_city_postal_code="3962" attribute_id_status="ACTIVE" geocode_gda_latitude="-38.670501000" geocode_gda_longitude="146.395343000" attribute_id_geocode_proj_sys="GDA94">Agnes</city>
我能够检索“ court_city_postal_code”和“ attribute_id_status”。 在这种情况下,如何检索城市名称“ Agnes”?
请在下面查看我的PHP代码:
$result = simplexml_load_string(trim(html_entity_decode($result)), 'SimpleXMLElement');
/** Instantiate Loop */
foreach ($result->area->city as $entry) {
$pna = htmlspecialchars_decode($entry->attributes()->suburb_city_postal_code, ENT_QUOTES);
$pna = str_replace("'", "''", $pna);
$str = htmlspecialchars_decode($entry->attributes()->attribute_id_status, ENT_QUOTES);
$str = str_replace("'", "''", $str);
echo $pna. "<br />";
echo $str . "<br />";
}
谢谢
从评论扩展:
只需在您的foreach
使用(string)$entry
:
foreach ($result->area->city as $entry) {
/* ... */
echo (string)$entry;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.