I'm building a SOAP
message for the first time and playing it with PHP.
The requirements are SOAP
version 1.1
with Style/Enconding: Document/Literal pattern.
Using SimpleXMLElement
:
$soapEnv = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope"></soap:Envelope>';
$soapEnvElement = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>' . $soapEnv);
$soapEnvElement->addChild('soap:Header');
$bodyElement = $soapEnvElement->addChild('soap:Body');
$bodyElement->addChild('node');
echo $soapEnvElement->asXML();
Expected output:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<node/>
</soap:Body>
</soap:Envelope>
Actual output:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<soap:node/>
</soap:Body>
</soap:Envelope>
Question
Why is this happening?
Is it possible to disable this behavior?