如何使用SimpleXML和PHP深入到SOAP命名空间如何使用、深入、空间、PHP

2023-09-04 22:46:40 作者:我、无人注意

全部,

我正在尝试访问SOAP响应中的元素ebl:Requester Credentials,但到目前为止还没有成功。我使用的是PHP SimpleXML。至少对我来说,问题是注册EBL命名空间-我在响应中得到的唯一结果是:

系列文章 kubesphere部署Bookinfo和管理流量

xmlns="urn:ebay:apis:eBLBaseComponents"

我尝试过:

$r =     $xml->registerXPathNamespace("ebl","urn:ebay:apis:eBLBaseComponents");
foreach($xml->xpath('ebl:RequesterCredentials') as $e){
$sig = (string) $e->NotificationSignature;

}

该元素按如下方式嵌套:

soapenv:信封->soapenv:Header->ebl:Requester Credentials->ebl:NotificationSignature

<;soapenv:信封xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">; <;soapenv:标题>; <;ebl:Requester Credentials xmlns:ns="urn:eBay:apis:eBLBaseComponents"xmlns:ebl="urn:eBay:apis:eBLBaseComponents"soapenv:mashUnderstand="0">; <;eBL:通知签名xmlns:ebl="urn:ebay:apis:eBLBaseComponents">;9hJXr9QTtck33I/4wg135A==<;/ebl:NotificationSignature>; <;/ebl:申请人凭证>; <;/soapenv:页眉>; <;soapenv:Body>; <;GetMemberMessagesResponse xmlns="urn:eBay:API:eBLBaseComponents">; <;Message>;foo<;/Message>; <;Timestamp>;2007-09-14T17:07:41.984Z<;/Timestamp>; <;/GetMemberMessagesResponse>; <;/soapenv:Body>; <;/soapenv:信封>;

关于如何访问此元素有什么建议吗?

推荐答案

经过几次不同的访问元素值尝试后,我得到了所需的内容,尽管它可能太过冗长。

$xml = simplexml_load_string(...);
$sig = (string) $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->children('urn:ebay:apis:eBLBaseComponents')->RequesterCredentials->NotificationSignature;