How return custom XML response in soapServer response?

╄→гoц情女王★ 提交于 2019-12-01 04:02:30

Phew!

This took me several retries and googling until I discovered what is wrong.
I think it can be classified as a bug in SoapVar.

I discovered that while SoapVar is perfectly capable of parsing an XML string, it cannot do so if the string contains an XML declaration like <?xml version="1.0" encoding="UTF-8"?>. So when you have a DOMDocument or a SimpleXMLElement, you first have to strip off the declaration before parsing the string by SoapVar.

for a DOMDocument this can be done by applying saveXML with a parameter equal to a DOMNode variable constructed from the dom itself, choosing any node but usually this will be the root node of course.

In my server php, I added the following:

$nodes = $dom -> getElementsByTagName ('cdhead');
$node = $nodes -> item(0);

$result = new SoapVar ($dom -> saveXML($node), XSD_ANYXML);

And now my result is OK:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://pse/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
    <ns1:mi102Response>
        <cdhead version="14"/>
    </ns1:mi102Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

As for the root name of the returned XML - I am sure I will find out a way to change that to whatever I want it to be (instead of the standard mi102Response generated by SoapVar)!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!