2

I'm picking up an old project that uses SOAP and WSDL, something that I'm not too familiar with. I have the following data structure defined in the WSDL (simplified in this example):

<s:complexType name="RequestPayment">
    <s:sequence>
        <s:element minOccurs="0" name="ProviderData" type="s0:ArrayOfFieldPairOfNameString"/>
    </s:sequence>
    <s:attribute name="CancelURL" type="s:string"/>
    <s:attribute name="ReturnURL" type="s:string"/>
</s:complexType>
<s:complexType name="ArrayOfFieldPairOfNameString">
    <s:sequence>
        <s:element maxOccurs="unbounded" minOccurs="0" name="Field" nillable="true" type="s0:PairOfNameString"/>
    </s:sequence>
</s:complexType>
<s:complexType name="PairOfNameString">
    <s:simpleContent>
        <s:extension base="s:string">
            <s:attribute name="Name" type="s:string" use="required"/>
        </s:extension>
    </s:simpleContent>
</s:complexType>

The project is using nusoap, a portion of my PHP looks like:

$payment['ProviderData'] = array(
    'Field' => array(
        'Name' => 'Foo',
    ),
);

Which is able to produce the following (again, simplified here):

<payment>
    <ProviderData>
        <Field Name="Foo" />
    </ProviderData>
</payment>

I'm not sure what format my PHP array should be in, in order to produce XML that looks like the following:

<payment>
    <ProviderData>
        <Field Name="name 1">value 1</Field>
        <Field Name="name 10">value 10</Field>
        <Field Name="name 2">value 2</Field>
    </ProviderData>
</payment>

I've tried setting a key called Value, !Value, and other variations, without success.

Any help would be appreciated. Thanks.

5
  • Why not using XMLWriter ? php.net/manual/en/book.xmlwriter.php Commented Apr 20, 2017 at 9:37
  • Because its a legacy project, in production and I don't want to have to change more than necessary. Commented Apr 20, 2017 at 9:39
  • So you are using a nusoap function to generate the xml from array? Or some selfmade function? stackoverflow.com/a/6743230/4916265 Commented Apr 20, 2017 at 9:42
  • Yes, I call the WSDL method, using nusoap, and it generates the XML, e.g. $this->client->call('Payment', $params) Commented Apr 20, 2017 at 9:45
  • Then look how the array is converted and how attributes and values are handled, what kind of name needed and so on. Commented Apr 20, 2017 at 9:47

2 Answers 2

1

After working backwards (converting the XML example into PHP), the format you want is:

$payment['ProviderData'] = array(
   'Field' => array (
     0 =>
     array (
       '!Name' => 'Foo',
       '!' => 'Bar',
     ),
     1 =>
     array (
       '!Name' => 'Amount',
       '!' => '98',
     ),
   )
);
Sign up to request clarification or add additional context in comments.

Comments

0

the best solution is to use a WSDL to php generator susch as the PackageGenerator project as you won't wonder how to construct the request

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.