[英]cannot read web service response in php
我正在用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"
...
我認為應該是:
$xmlstring = $getUser->webserviceaction->any;
然后循環應為:
foreach ($xml->User->ActionItems as $res) {
echo "Title: " . $res->Title . "\n";
}
簡單XML 區分大小寫。 。 而且沒有result
元素,那是頂級XML對象的標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.