Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a SOAP request with PHP - how do I add attributes to the XML tags?

Tags:

php

soap

xml

I am trying to generate the following XML in my SOAP call:

<CResponse>
    <ID>int</ID>
    <Response Action="Apply">
        <Question ID="$someint">
            <Responses>
                <Response ID="$someotherint" />
                <Response ID="$yetanotherint" />
            </Responses>
        </Question>
    </Response>
</CResponse>

I can create most of the call just fine - I've finally picked up that nested arrays are my friends - but I have no idea how to add those ID="$int" and Action="Apply" attributes to the various tags. I'm sure this is fairly easy, but I just can't figure it out.

TIA.

like image 830
benjy Avatar asked Sep 10 '09 06:09

benjy


1 Answers

You should be able to add attributes with following syntax:

array("foo" => array("_" => "cheese", "bar"=>"moo"));

This should produce following XML

<foo bar="moo">cheese</foo>
like image 169
JJ. Avatar answered Nov 11 '22 05:11

JJ.