How return custom XML response in soapServer response?

后端 未结 1 1396
挽巷
挽巷 2021-01-12 12:25

I am setting up a SOAP webservice which takes XML input and has to return custom XML output. All this is defined in a WSDL. I apply soapServer for this (until someone says i

1条回答
  •  梦谈多话
    2021-01-12 12:50

    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 . 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:

    
    
    
        
            
        
    
    
    

    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)!!

    0 讨论(0)
提交回复
热议问题