2

I am trying to create a soap request and, I need to convert soap xml to a php array. but I am stuck in a position where I can't figure out how to set attributes to array properly. I am very new to soap and good explanation will be appreciated. Here is what I have done so far.

what i want to create

<arg0>
    <ns2:coverType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:type="ns2:FamilyCoverType">
        <ns2:abc>1978-04-03</ns2:abc>
        <ns2:def>1980-04-03</ns2:def>
        <ns2:pqr>2016-04-10</ns2:pqr>
        <ns2:xyz>2016-05-03</ns2:xyz>
    </ns2:coverType>
</arg0>

My array

$data = array(
        'arg0' => array(
            'coverType' => array(
                'abc' => $abc,
                'def' => $def,
                'pqr' => $pqr,
                'xyz' => $xyz,
            )
        )
    );

Everything is fine except

xsi:type="ns2:FamilyCoverType"

How can I set above attribute in my array?? Pls Help.

4
  • Do you have a WSDL URL you can add to the question? Commented Feb 8, 2017 at 3:31
  • @KrisPeeling I'm sorry. I cannot share since it is sensitive information. Commented Feb 8, 2017 at 4:30
  • Just to confirm, you are asking how to convert XML to PHP array? or array to XML? Commented Feb 8, 2017 at 18:39
  • I'm converting PHP array to SOAP XML. Commented Feb 9, 2017 at 4:47

2 Answers 2

1

I strongly advise you to use a WSDL to php generator such as PackageGenerator as you won't wonder at all how to structure your request. If you use Eclipse PDT or any other good IDE with the generated PHP SDK, you'll send the requests in a few seconds. Moreover, you'll handle very easily the response as you'll have known PHP objects as they would have been generated as PHP classes within the SDK.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the response. I'll work on that.
1

After two hectic weeks I could finally came to a solution. So I'm posting my answer here so someone could save his time.

we can do above thing like this easily,

$param = new \SoapVar('
           <arg0>
               <ns2:coverType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:FamilyCoverType">
                   <ns2:abc>' . $data['abc'] . '</ns2:abc>
                    <ns2:def>' . $data['def'] . '</ns2:def>
                    <ns2:pqr>' . $data['pqr'] . '</ns2:pqr>
                    <ns2:xyz>' . $data['xyz'] . '</ns2:xyz>
               </ns2:coverType>
           </arg0>', XSD_ANYXML);

Then we can get the response like this,

$response = $client->your_calling_function($param);

As far as it seems,

XSD_ANYXML

is the key.

If someone still having trouble with that I am really happy to help. do not hesitate to ask for help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.