【发布时间】:2015-07-18 08:45:34
【问题描述】:
我正在使用 PHP 调用 Web 服务,但在处理响应时遇到了困难。
如果我对响应进行 var_dump,这是 Web 服务返回的消息:
stdClass Object
(
[webserviceaction] => stdClass Object
(
[any] =>
<result xmlns="" corpname="test"><user id="tester">
<inbox><actionitems><title>View transcript</title>
<actionitemurl>../MainView.aspx?tab_page_id=-8&Reset=TRUE</actionitemurl>
</actionitems><actionitems>
.....
</result>
试图将公司名读取为
$getUser->Webserviceaction->Result['corpName'];
它显示 NULL。不确定如何读取对象内部的 xml。
尝试根据http://board.phpbuilder.com/showthread.php?10370637-Cannot-read-web-service-response获取最后的响应
仍然无法获取值。 这是代码。
echo "RESPONSE:\n" . $client->__getLastResponse() . "\n";
$xmlstring = $getUser->webserviceaction->any;
$xml = new SimpleXMLElement($xmlstring);
foreach ($xml->result->user->inbox->actionitems as $res)
echo "Title" . $res->title . "\n";
请指教。
这是我打印 $xml 时看到的内容
resultobject(SimpleXMLElement)#8 (2) {
["@attributes"]=>
array(1) {
["corpName"]=>
string(4) "test"
}
["User"]=>
object(SimpleXMLElement)#9 (4) {
["@attributes"]=>
array(1) {
["id"]=>
string(6) "tester"
}
["Inbox"]=>
object(SimpleXMLElement)#10 (1) {
["ActionItems"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#13 (2) {
["Title"]=>
string(15) "View transcript"
["ActionItemUrl"]=>
string(46) "../MainView.aspx?tab_page_id=-8&Reset=TRUE"
}
[1]=>
object(SimpleXMLElement)#14 (2) {
["Title"]=>
string(32) "View Training Exemption Requests"
["ActionItemUrl"]=>
string(40) "../PendingExemptionRequests.aspx?wp=1"
...
【问题讨论】:
标签: php xml web-services soap-client