SimpleXMLElement输出格式

I'm using SimpleXMLElement for create datafeed page: Here the code:

$xml = new SimpleXMLElement("<Products />");

foreach ($products as $pro) {
    $track = $xml -> addChild('Product');
    $track -> addChild('simple_sku', "<![CDATA[ ABC ]]>");
}
Header('Content-type: text/xml');
print($xml -> asXML());

and the output:

<Products>
    <Product>
        <simple_sku><![CDATA[ ABC ]]></simple_sku>
    </Product>
</Products>

I want to know how to turn output into format like this:

<Products>
    <Product>
        <simple_sku>
            <![CDATA[ ABC ]]>
        </simple_sku>
    </Product>
<Products>

Thanks you a lot.

It's not possible with SimpleXML so I advice you to use DOMDocument.

Usage example:

$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($simpleXml->asXML());