title: PHP soap request with an element attribute and child elements
body: <p>Below is my code to construct the soap request.  I can create a client, but to update a client, I need the client number as an attribute in the client tag.  </p>
  
  <pre><code>$urn = '&lt;SOME DEFINITION&gt;';
  $urn1 = '&lt;SOME DEFINITION&gt;';
  $urn2 = '&lt;SOME DEFINITION&gt;';
  
  // Main descriptive content of the client
  $clientType = $clientInfo['clt_type'];
  $companyName = $clientInfo['clt_name'];
  $mainPaymentMethod = '0001';
  $mainPaymentCondition = '0003';
  
  /* Build sales portion */
  $sales_city = $clientInfo['clt_sales_city'];
  $sales_area1 = $clientInfo['clt_sales_state'];
  $sales_zipCode = $clientInfo['clt_sales_zipcode'];
  $sales_countryCode = $clientInfo['clt_sales_country'];
  $sales_address = $clientInfo['clt_sales_address'];
  $sales_address_two = $clientInfo['clt_sales_address2'];
  
  $salesGeneralFitness = 'MAIN';
  $salesBillingFitness = 'MAIN';
  
  $salesAddressParams[] = new SoapVar($sales_address, XSD_STRING, null, $urn1, 'Address', $urn1);
  $salesAddressParams[] = new SoapVar($sales_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1);
  $salesAddressParams[] = new SoapVar($sales_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1);
  $salesAddressParams[] = new SoapVar($sales_city, XSD_STRING, null, $urn1, 'City', $urn1);
  $salesAddressParams[] = new SoapVar($salesGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2);
  $salesAddressParams[] = new SoapVar($salesBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2);
  $salesAddressParams[] = new SoapVar($sales_area1, XSD_STRING, null, $urn2, 'Area1', $urn2);
  $salesAddressParams[] = new SoapVar($sales_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2);
  
  $SalesAddress = new SoapVar($salesAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2);
  /* End of sales portion */
  
  /* Build financial portion */
  $financial_city = $clientInfo['clt_financial_city'];
  $financial_area1 = $clientInfo['clt_financial_state'];
  $financial_zipCode = $clientInfo['clt_financial_zipcode'];
  $financial_countryCode = $clientInfo['clt_financial_country'];
  $financial_address = $clientInfo['clt_financial_address'];
  $financial_address_two = $clientInfo['clt_financial_address2'];
  
  $financialGeneralFitness = 'MAIN';
  $financialBillingFitness = 'MAIN';
  
  $financialAddressParams[] = new SoapVar($financial_address, XSD_STRING, null, $urn1, 'Address', $urn1);
  $financialAddressParams[] = new SoapVar($financial_address_two, XSD_STRING, null, $urn1, 'AddressComplement', $urn1);
  $financialAddressParams[] = new SoapVar($financial_zipCode, XSD_STRING, null, $urn1, 'ZipCode', $urn1);
  $financialAddressParams[] = new SoapVar($financial_city, XSD_STRING, null, $urn1, 'City', $urn1);
  $financialAddressParams[] = new SoapVar($financialGeneralFitness, XSD_STRING, null, $urn2, 'GeneralFitness', $urn2);
  $financialAddressParams[] = new SoapVar($financialBillingFitness, XSD_STRING, null, $urn2, 'BillingFitness', $urn2);
  $financialAddressParams[] = new SoapVar($financial_area1, XSD_STRING, null, $urn2, 'Area1', $urn2);
  $financialAddressParams[] = new SoapVar($financial_countryCode, XSD_STRING, null, $urn2, 'CountryCode', $urn2);
  
  $FinancialAddress = new SoapVar($financialAddressParams, SOAP_ENC_OBJECT, null, $urn2, 'Address', $urn2);
  
  /* Build The rest of the required (not used) soap request */
  
  $LogInfo = new SoapVar('', XSD_STRING, null, $urn2, 'LogInfo', $urn2);
  $CommonName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CommonName', $urn2);
  $CompanyName = $StartDate = new SoapVar($companyName, XSD_STRING, null, $urn2, 'CompanyName', $urn2);
  $AreImplicitMandatesOk = new SoapVar('false', XSD_STRING, null, $urn2, 'AreImplicitMandatesOk', $urn2);
  $ParentInfo = new SoapVar('', XSD_STRING, null, $urn2, 'ParentInfo', $urn2);
  $UserProperties = new SoapVar('', XSD_STRING, null, $urn2, 'UserProperties', $urn2);
  $StartDate = new SoapVar(date('Y-m-d', time()), XSD_STRING, null, $urn2, 'StartDate', $urn2);
  $MainPaymentMethod = new SoapVar($mainPaymentMethod, XSD_STRING, null, $urn2, 'MainPaymentMethod', $urn2);
  $MainPaymentCondition = new SoapVar($mainPaymentCondition, XSD_STRING, null, $urn2, 'MainPaymentCondition', $urn2);
  $ClientType = new SoapVar($clientType, XSD_STRING, null, $urn2, 'ClientType', $urn2);
  $MandateInfo = new SoapVar('', XSD_STRING, null, $urn2, 'MandateInfo', $urn2);
  $VATInfo = new SoapVar('', XSD_STRING, null, $urn2, 'VATInfo', $urn2);
  
  /* Set the body content */
  $Body[] = $LogInfo;
  $Body[] = $CommonName;
  $Body[] = $CompanyName;
  $Body[] = $StartDate;
  $Body[] = $MainPaymentMethod;
  $Body[] = $MainPaymentCondition;
  $Body[] = $ClientType;
  $Body[] = $SalesAddress;
  $Body[] = $FinancialAddress;
  $Body[] = $AreImplicitMandatesOk;
  $Body[] = $ParentInfo;
  $Body[] = $UserProperties;
  $Body[] = $MandateInfo;
  $Body[] = $VATInfo;
  
     /* Build entire soap request here */
  $data = new SoapVar($Body, SOAP_ENC_OBJECT, null, $urn, 'Client', $urn);
  $parameters['Client'] = $data;
  </code></pre>
  
  <p>This produces:</p>
  
  <pre><code>     &lt;urn:Client&gt; &lt;- Add attribute to this tag
          &lt;urn2:LogInfo&gt;
          &lt;/urn2:LogInfo&gt;
          &lt;urn2:CommonName&gt;Some Value&lt;/urn2:CommonName&gt;
          &lt;urn2:CompanyName&gt;Some Value&lt;/urn2:CompanyName&gt;
          &lt;urn2:StartDate&gt;2016-01-01&lt;/urn2:StartDate&gt;
          &lt;urn2:MainPaymentMethod&gt;0001&lt;/urn2:MainPaymentMethod&gt;
          &lt;urn2:MainPaymentCondition&gt;0003&lt;/urn2:MainPaymentCondition&gt;
          &lt;urn2:ClientType&gt;XXX&lt;/urn2:ClientType&gt;
          &lt;urn2:Address&gt;
             &lt;urn1:ZipCode&gt;55555&lt;/urn1:ZipCode&gt;
             &lt;urn1:City&gt;City&lt;/urn1:City&gt;
             &lt;urn2:GeneralFitness&gt;MAIN&lt;/urn2:GeneralFitness&gt;
             &lt;urn2:BillingFitness&gt;MAIN&lt;/urn2:BillingFitness&gt;
             &lt;urn2:Area1&gt;NY&lt;/urn2:Area1&gt;
             &lt;urn2:CountryCode&gt;US&lt;/urn2:CountryCode&gt;
          &lt;/urn2:Address&gt;
          &lt;urn2:AreImplicitMandatesOk&gt;false&lt;/urn2:AreImplicitMandatesOk&gt;
          &lt;urn2:ParentInfo urn1:dataOmitted="true"&gt;
          &lt;/urn2:ParentInfo&gt;
          &lt;urn2:UserProperties urn1:dataOmitted="true"&gt;
          &lt;/urn2:UserProperties&gt;
          &lt;urn2:MandateInfo urn1:dataOmitted="true"&gt;
          &lt;/urn2:MandateInfo&gt;
          &lt;urn2:VATInfo&gt;
          &lt;/urn2:VATInfo&gt;
       &lt;/urn:Client&gt;
  </code></pre>
  
  <p>But what I need is all of that above, and an attribute in the Client tag with all of the child elements:</p>
  
  <pre><code>&lt;urn:Client Attr1='XXXX1121111'&gt;
  </code></pre>
  
  <p>I went through all of the posts that I could find in SO.  I cannot produce an attribute to element that has child elements.  I have tried using XSD_ANYXML, and built a view to insert into a SoapVar(), and it did not work, because I needed the namespaces.  This is most likely a repeat of another question, but those have been unanswered.  </p>
  
  <p>Below are just some of the posts I have been to on this issue:</p>
  
  <p><a href="https://stackoverflow.com/questions/11847233/soap-request-with-php">SOAP request with PHP</a>  </p>
  
  <p><a href="https://stackoverflow.com/questions/8577016/create-soap-request-with-element-attribute-using-zend-soap-client-and-stdobject">Create SOAP request with element attribute using Zend_Soap_Client and stdObject</a></p>
  
  <p><a href="https://stackoverflow.com/questions/28872224/send-other-attributes-with-xsitype-attribute-in-soap-request-php">Send other attributes with xsi:type attribute in Soap Request PHP</a></p>
  
  <p><a href="https://stackoverflow.com/questions/23339318/soap-request-from-php-is-not-working?rq=1">SOAP Request from PHP is not working</a></p>