XMLwriter returns empty string. Can anyone see a reason?
<p>This function should create an xml file that eventually gets passed to a curl request in the controller, and eventually up to an accounting api. The curl request works fine when i pass in a static XML file. </p>

<p>The code here should generate a dynamic xml file based on the client that is being created. </p>

<p>For what ever reason, it is returning an empty string. </p>

<p>Some of the fields allow null. </p>

<p>Any ideas would be greatly appreciated. </p>

<p>

<pre><code>$writer = new XMLWriter($xmlString);
// Output directly to the user 
$writer-&gt;openMemory();

$writer-&gt;openURI('php://output'); 
$writer-&gt;startDocument('1.0');
$writer-&gt;writeAttribute('encoding', 'utf-8');

$writer-&gt;startElement('request');
$writer-&gt;writeAttribute('method', 'client.create');

$writer-&gt;setIndent(true); 

$writer-&gt;startElement('client'); 
//---------------------------------------------------- 

$writer-&gt;writeElement('first_name', $org-&gt;first_name);
$writer-&gt;writeElement('last_name', $org-&gt;last_name);
$writer-&gt;writeElement('organization', $org-&gt;name); 
$writer-&gt;writeElement('email', $org-&gt;contact_email);
$writer-&gt;writeElement('username', $org-&gt;contact_name);
$writer-&gt;writeElement('password');

//---------------------------------------------------- 

$writer-&gt;startElement('contacts'); 

$writer-&gt;startElement('contact'); 

    $writer-&gt;writeElement('username', $org-&gt;contact_name);
    $writer-&gt;writeElement('first_name', $org-&gt;first_name);
    $writer-&gt;writeElement('last_name', $org-&gt;last_name);
    $writer-&gt;writeElement('email', $org-&gt;contact_email); 
    $writer-&gt;writeElement('phone1', $org-&gt;contact_phone);
    $writer-&gt;writeElement('phone2'); 

// contact 
$writer-&gt;endElement(); 

// End contacts 
$writer-&gt;endElement(); 
//---------------------------------------------------- 

$writer-&gt;writeElement('work_phone', $org-&gt;contact_phone);
$writer-&gt;writeElement('home_phone', $org-&gt;contact_phone);
$writer-&gt;writeElement('mobile', $org-&gt;contact_phone);
$writer-&gt;writeElement('fax', $org-&gt;contact_phone);
$writer-&gt;writeElement('language', 'en');
$writer-&gt;writeElement('currency_code', 'USD');
$writer-&gt;writeElement('phone1', $org-&gt;contact_phone);
$writer-&gt;writeElement('notes');

// primary address
$writer-&gt;writeElement('p_street1');
$writer-&gt;writeElement('p_city');
$writer-&gt;writeElement('p_state');
$writer-&gt;writeElement('p_code');

// secondary address
$writer-&gt;writeElement('s_street1');
$writer-&gt;writeElement('s_city');
$writer-&gt;writeElement('s_state');
$writer-&gt;writeElement('s_code');

$writer-&gt;writeElement('vat_name');
$writer-&gt;writeElement('vat_number');


// End channel 
$writer-&gt;endElement(); 

// End request
$writer-&gt;endElement();  

$writer-&gt;endDocument(); 

$currentMemory = $writer-&gt;outputMemory();

$writer-&gt;flush();

return $currentMemory;
}
</code></pre>