title: Convert XML to object in PHP a update values of some node and again convert object to XML?
body: <p>I am dealing with multiple APIs. Please find some steps.<br>
  <strong>Step1</strong>  I have got the first API's result as below. 
      <strong>Let's say I have got the following response.</strong></p>
  
  <pre><code>     $xml = '&lt;soap:Envelope
       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
        &lt;soap:Body&gt;
          &lt;Response
            xmlns="http://schemas.martin-group.com/test"&gt;
            &lt;Result&gt;
              &lt;![CDATA[
              &lt;AccountInfo&gt;&lt;CusAccount Action="Add" AccountID="2046369" DesiredCycleID="0" Name="" 
               Corporation="" Cycle=""&gt;&lt;AccountType&gt;&lt;CusAccountType AccountTypeID="100001" Version="1" 
               AccountTypeCode="BUS " AccountType="Business" MonthlyBillingMethod="P" /&gt;&lt;/AccountType&gt; 
               &lt;InvoiceFormat&gt;&lt;ICInvoiceFormat InvoiceFormatID="1" UserID="10490655" 
               AddressAdjustmentY="0" AddressWidth="3500"/&gt;&lt;/InvoiceFormat&gt;&lt;/CusAccount&gt; 
               &lt;/AccountInfo&gt;]]&gt;
           &lt;/Result&gt;
         &lt;/Response&gt;
      &lt;/soap:Body&gt;
     &lt;/soap:Envelope&gt;';    
  </code></pre>
  
  <p><strong>Step2</strong> I have converted XML to XML Object. </p>
  
  <pre><code>     $soap = simplexml_load_string($xml);
       $soap-&gt;registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
       $object = $soap-&gt;xpath('//soap:Envelope/soap:Body')[0]-&gt;Response;
       $cdata = $object-&gt;Result;
       $cdata_as_xml = simplexml_load_string($cdata);
  </code></pre>
  
  <p><strong>Step3</strong> I have updated some node's values as follows.</p>
  
  <pre><code>    1. $cdata_as_xml-&gt;CusAccount['Action'] = 'Edit'
      2. $cdata_as_xml-&gt;CusAccount['DesiredCycleID'] = '1'
      3. $cdata_as_xml-&gt;CusAccount-&gt;AccountType-&gt;CusAccountType['AccountTypeID'] = '1000023'
  </code></pre>
  
  <p><strong>Step4</strong> Now I need this updated XML to pass in another API as body as follows:</p>
  
  <pre><code> $xml = '&lt;CusAccount Action="Edit" AccountID="2046369" DesiredCycleID="1" Name="" 
               Corporation="" Cycle=""&gt;&lt;AccountType&gt;&lt;CusAccountType AccountTypeID="1000023" Version="1" 
               AccountTypeCode="BUS " AccountType="Business" MonthlyBillingMethod="P" /&gt;&lt;/AccountType&gt; 
               &lt;InvoiceFormat&gt;&lt;ICInvoiceFormat InvoiceFormatID="1" UserID="10490655" 
               AddressAdjustmentY="0" AddressWidth="3500"/&gt;&lt;/InvoiceFormat&gt;&lt;/CusAccount&gt;';
  </code></pre>
  
  <p><strong>But $cdata_as_xml something look like as follows:</strong></p>
  
  <pre><code>    SimpleXMLElement Object ( 
           [CusAccount] =&gt; SimpleXMLElement Object 
               ( [@attributes] =&gt; Array ( [Action] =&gt; Edit [AccountID] =&gt; 2046414 [DesiredCycleID] =&gt; 1 
                  [Name] =&gt; [Corporation] =&gt; [Cycle] =&gt; ) 
                  [AccountType] =&gt; SimpleXMLElement Object 
                     ( [CusAccountType] =&gt; SimpleXMLElement Object ( 
                         [@attributes] =&gt; Array ( [AccountTypeID] =&gt; 1000023 [Version] =&gt; 1 
                           [ModifyDate] =&gt; 5/21/2009 9:46:00 AM [UserID] =&gt; 10120452 
                           [AccountTypeCode] =&gt; BUS [AccountType] =&gt; Business 
                           [MonthlyBillingMethod] =&gt; P 
                     ) 
                )
             ) 
             [InvoiceFormat] =&gt; SimpleXMLElement Object 
               ( [ICInvoiceFormat] =&gt; SimpleXMLElement Object 
                  ( [@attributes] =&gt; Array ( [InvoiceFormatID] =&gt; 1 [UserID] =&gt; 10490655 
                      [AddressAdjustmentY] =&gt; 0 [AddressWidth] =&gt; 3500 ) 
                   )
                )
              )
            )
  </code></pre>
  
  <p>How can I get pure XML, not XML Object? </p>
  
  <p>Any help on this would be appreciated.</p>
  
  <p>Thank you.</p>