I am trying to create a SOAP request for a paypal express checkout with SimpleXML. However, I am experiencing a behaviour I don't yet understand.
The envelope and its header are generated this way:
$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'); Which yields the following output:
<?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> Every node is now prefixed with SOAP-ENV, which is not what I want. Only the root node and header should be prefixed with SOAP-ENV, the other tags should get the defined namespace prepended in addChild().
The desired output should be:
<?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> What am I doing wrong here?
SOAP-ENVprefix.