【发布时间】:2013-05-22 17:02:18
【问题描述】:
我正在使用 SOAP ui 完美地获得一个 SOAP 调用的 SOAP 响应,但是当我在 php 中调用它时,我无法遍历所需的元素(在这种情况下为 CreditId),我想要的。
以下是我使用 SOAP ui 得到的 SOAP 响应:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
<n0:getProjectCreditListResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<EUserGuid>33/XIcx+3/GxWABQVoJXWA==</EUserGuid>
<EtCurrCreditList>
<item>
<PhaseId/>
<CreditcategoryDescrption>Project Information Forms</CreditcategoryDescrption>
<CreditId>CSD1GSP1L-1000008140</CreditId>
</item>
<item>
<PhaseId/>
<CreditcategoryDescrption>Project Information Forms</CreditcategoryDescrption>
<CreditId>CSD1GSP2L-1000008140</CreditId>
</item>
</EtCurrCreditList>
<EtErrorLogInfo/>
</n0:getProjectCreditListResponse>
</soap-env:Body>
</soap-env:Envelope>
现在我已经浏览了网站上的各种类似问题,建议这样做以获得所需的元素:
$client = new SoapClient('wsdl file path',array('trace'=>1,'exceptions'=>1);
$res = $client->getCreditFormDataXml(array(input arguments));
$xml = simplexml_load_string($res);
$xml->registerXPathNamespace('soap-env', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('n0', 'urn:sap-com:document:sap:soap:functions:mc-style');
foreach ($xml->xpath('//EtCurrCreditList//item//CreditId') as $item)
{
var_dump($item);
}
但是我得到一个错误说明
警告:simplexml_load_string() 期望参数 1 是字符串
我尝试将 $res 变量转换为字符串,但它给出的错误是
stdClass 类的对象无法转换为字符串
但如果我执行 var_dump($res),我会得到如下输出:
object(stdClass)[2]
public 'EUserGuid' => string 'ß×!Ì~ßñ±X�PV‚WX' (length=16)
public 'EtCurrCreditList' =>
object(stdClass)[3]
public 'EtErrorLogInfo' =>
object(stdClass)[4]
为什么代码没有进入 EtCurrCreditList 的子节点,以便我可以处理它以获得所需的值。 - 已解决
最终输出:
stdClass Object
(
[EUserGuid] => ß×!Ì~ßñ±XPV‚WX
[EtCurrCreditList] => stdClass Object
(
[item] => Array
(
[0] => stdClass Object
(
[PhaseId] =>
[PhaseDescription] =>
[CreditcategoryId] => CSD1GSL-1000008140
[CreditcategoryDescrption] => Project Information Forms
[CreditId] => CSD1GSP1L-1000008140
)
[1] => stdClass Object
(
[PhaseId] =>
[PhaseDescription] =>
[CreditcategoryId] => CSD1GSL-1000008140
[CreditcategoryDescrption] => Project Information Forms
[CreditId] => CSD1GSP2L-1000008140
)
[2] => stdClass Object
(
[PhaseId] =>
[PhaseDescription] =>
[CreditcategoryId] => CSD1GSL-1000008140
[CreditcategoryDescrption] => Project Information Forms
[CreditId] => CSD1GSP3L-1000008140
)
)
)
[EtErrorLogInfo] => stdClass Object
(
)
【问题讨论】:
-
试试这个。这可能会解决您的疑问stackoverflow.com/questions/5048685/…
-
您好,感谢您的回复,我只按照这些步骤操作,但问题是 simplexml_load_string 函数无法将 $res 识别为字符串,,那么我该如何先解决这个问题。我还尝试复制 xml 并将其用作输入,然后执行上述代码,它提供了所有 creditID,但不是通过使用 $res 作为输入
标签: php soap wsdl soapui soap-client