I am trying to create a SOAP request for an API like below
in some case I will need to add other tags under <ticketId>int</ticketId>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetServiceTicket xmlns="http://connectwise.com">
<credentials>
<CompanyId>string</CompanyId>
<IntegratorLoginId>string</IntegratorLoginId>
<IntegratorPassword>string</IntegratorPassword>
</credentials>
<ticketId>int</ticketId>
</GetServiceTicket>
</soap:Body>
</soap:Envelope>
What is the correct way in PHP to write this code not using old and simple fashion string concatenation technique.
I thought about using SimpleXMLElement
so here is what I have done
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><xml/>');
$envelop = $xml->addChild('soap:Envelope');
$envelop->addAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
$envelop->addAttribute('xmlns:xsd','http://www.w3.org/2001/XMLSchema');
$envelop->addAttribute('xmlns:soap','http://schemas.xmlsoap.org/soap/envelope/');
$body = $envelop->addChild('soap:Body');
$action = $body->addChild('GetServiceTicket');
$action->addAttribute('xmlns','http://connectwise.com');
$credentials = $action->addChild('credentials');
$CompacnyId = $credentials->addChild('CompacnyId','string');
$IntegratorLoginId = $credentials->addChild('IntegratorLoginId','string');
$IntegratorPassword = $credentials->addChild('IntegratorPassword','string');
$ticketId = $action->addChild('ticketId', 'int');
Header('Content-type: text/xml');
print($xml->asXML());
But the output show up like this
<?xml version="1.0" encoding="utf-8"?>
<xml>
<Envelope xsi="http://www.w3.org/2001/XMLSchema-instance" xsd="http://www.w3.org/2001/XMLSchema" soap="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<GetServiceTicket xmlns="http://connectwise.com">
<credentials>
<CompacnyId>string</CompacnyId>
<IntegratorLoginId>string</IntegratorLoginId>
<IntegratorPassword>string</IntegratorPassword>
</credentials>
<ticketId>int</ticketId>
</GetServiceTicket>
</Body>
</Envelope>
</xml>
How can I correct the output?