xml
我的一个方法$api->responseXML 在页面上打印出来显示是一些标准的xml,请问我该如何解码
如下:
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
<S:Body>
<imagead id="446757" owner="@" class="1" profiles="_all_" groups="" recursive="false">
<displayPreference>2</displayPreference>
<preference>98</preference>
<imageUri>http://www.iisp.com/images/v4/logo.gif</imageUri>
<adLink>http://www.iisp.com</adLink>
</imagead>
</S:Body>
</S:Envelope>
我解码他的代码如下 求高手指教
$dom=new DOMDocument();
$dom->load($api->responseXML);//如何把它读出来
$messages = $dom -> getElementsByTagName("imagead");//图片ad
foreach($messages as $book){
//get id
$id = $book->getAttribute('id');
//get displayPreference
$dis = $book->getElementsByTagName('displayPreference');
$displayPreference = $dis->item(0)->nodeValue;
//get preference
$pre = $book->getElementsByTagName('preference');
$preference = $pre->item(0)->nodeValue;
// get imageUri
$ima = $book->getElementsByTagName('imageUri');
$imageUri = $ima->item(0)->nodeValue;
// get adLink
$ad = $book->getElementsByTagName('adLink');
$adLink = $ad->item(0)->nodeValue;
//save data
$imageadInfo['id'] = $id;
$imageadInfo['displayPreference'] = $displayPreference;
$imageadInfo['preference'] = $preference;
$imageadInfo['imageUri'] = $imageUri;
$imageadInfo['adLink'] = $adLink;
//save info
$imageadInfos[] = $imageadInfo;
}
print_r($imageadInfos);
[解决办法]
问题是什么?
[解决办法]
是 $dom->loadXML($api->responseXML);
而不是 $dom->load($api->responseXML);
因为 $api->responseXML 是串而不是文件名