Sunday, 24 June 2018

PHP SoapClient removing element with name

I have a WSDL that has an element that requires an attribute:

<xsd:complexType name="claim">
  <xsd:annotation>
    <xsd:documentation>Claim Element</xsd:documentation>
  </xsd:annotation>
  <xsd:sequence>
    <!-- other elements removed -->
  </xsd:sequence>
  <xsd:attribute name="claimId" type="xsd:nonNegativeInteger" use="required" />
</xsd:complexType>

In terms of generated xml, it should look like:

<claims>
    <claim claimId="1">
        <!-- elements removed -->
    </claim>
    <!-- more claims -->
</claims>

Within a foreach loop I am putting together an array of elements and using the attribute as part of the key:

//$claim = array of key/value pairs
$claim = [...];
$claim = new \SoapVar($claim, SOAP_ENC_OBJECT, null, null, 'claim claimId="' . ($key+1) . '"');
$claims['claim claimId="'.($key+1).'"'] = $claim;

When it comes to passing this to the SoapClient, the elements get removed:

//$client = new \SoapClient($wsdl);
$client->checkClaims($claims);

But all I'm getting is:

<claims />

How do I get my soap client to parse the claim elements correctly in the soap call?



from PHP SoapClient removing element with name

No comments:

Post a Comment