goorj goorj - 5 months ago 71
PHP Question

How to add attributes to soapVars

I'd like to create soapVars with attributes like this:

<tag attr="xxx">yyy</tag>


Is this possible with the SoapVar constructor, but without using XSD_ANYXML and raw xml strings?

Answer

The best way to do it is:

<?php 
 $tag['_'] = 'yyy'; 
 $tag['attr'] = 'xxx'; 
 $tagVar = new SoapVar($tag, SOAP_ENC_OBJECT); 

?> 

the result would be:

<tag attr="xxx">yyy</tag>