xml - How to dynamically create a SOAP request using PHP -
i trying create soap request api below in case need 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 correct way in php write code not using old , simple fashion string concatenation technique.
i thought using simplexmlelement
so here 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 output show 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 correct output?