I've seen this question answered elsewhere but I still can't make it work, so I need some further clarification:
The example given was:
$tag['_'] = 'yyy';
$tag['attr'] = 'xxx';
$tagVar = new SoapVar($tag, SOAP_ENC_OBJECT);
The generated xml would be:
<tag attr="xxx">yyy</tag>
However, I'm getting
<tag>
<_>yyy</_>
<attr>xxx</attr>
</tag>
So, is anything else needed to make it work as expected? Some kind of configuration in the SoapServer class or in the WSDL even?
To complicate things a bit more, the element is namespaced, so actually I'm looking for a way to get
<ns:tag attr="xxx">yyy</ns:tag>
The PHP soap function are so mad and I've never found out what was so wrong in it. I was trying to connect and update data into zimbra via SOAP API, and had many issues cuz of it. So I used SimpleXMLElement & Curl :)
There you can build your XML like this :
$xml = new SimpleXMLElement('<soap></soap>'); // create your base
$xml = $xml->addChild('tag', str_replace('&', '&', 'yyy')); // see addChild in docs
$xml->attr = 'xxx'; // escaping content rather than addAttribute which does not
echo $xml->asXML(); // which returns : <tag>yyy<attr>xxx</attr></tag>
For the namespace, there is a namespace argument in addChild, but this does not output what you want ...
$xml = $xml->addChild('tag', str_replace('&', '&', 'yyy'), 'ns');
$xml->attr = 'xxx';
echo $xml->asXML(); // which returns : <tag>yyy<attr>xxx</attr></tag>
PS : if you are running in browser, dont forget to htmlspecialchars
the echos :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With