我正在尝试使用SimpleXML为paypal express签出创建SOAP请求。然而,我正在经历一种我还不明白的行为。
信封及其标题的生成方式如下:
$envelope = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:ebay:apis:eBLBaseComponents"
xmlns:ns2="urn:ebay:api:PayPalAPI"
/>
');
$header = $envelope->addChild('SOAP-ENV:Header');
$requesterCredentials = $header->addChild('ns2:RequesterCredentials');
$credentials = $requesterCredentials->addChild('ns1:Credentials');
$credentials->addChild('ns1:Username', 'foo');
$credentials->addChild('ns1:Password', 'bar');
这将产生以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:ebay:apis:eBLBaseComponents"
xmlns:ns2="urn:ebay:api:PayPalAPI">
<SOAP-ENV:Header>
<SOAP-ENV:RequesterCredentials>
<SOAP-ENV:Credentials>
<SOAP-ENV:Username>foo</SOAP-ENV:Username>
<SOAP-ENV:Password>bar</SOAP-ENV:Password>
</SOAP-ENV:Credentials>
</SOAP-ENV:RequesterCredentials>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>
每个节点现在都带有前缀
SOAP-ENV
,这不是我想要的。只有根节点和头应该加前缀
肥皂油
,其他标记应在
addChild()
.
所需输出应为:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="urn:ebay:apis:eBLBaseComponents"
xmlns:ns2="urn:ebay:api:PayPalAPI">
<SOAP-ENV:Header>
<ns2:RequesterCredentials>
<ns1:Credentials>
<ns1:Username>foo</ns1:Username>
<ns1:Password>bar</ns1:Password>
</ns1:Credentials>
</ns2:RequesterCredentials>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>
我在这里做错了什么?