Reputation: 2202
I'm trying to load Xml from a file using CakePHP's XML utility.
Is there a way when I convert it back to a string to save to a file that it can recreate line breaks and indentation of elements?
$xml = Xml::build('../webroot/files/test.xml');
$xmlData = Xml::toArray($xml);
$xmlObject = Xml::fromArray($xmlData);
$xmlString = $xmlObject->asXML();
file_put_contents('../webroot/files/test2.xml', $xmlString);
The test2.xml is now saved as a single line.
Upvotes: 0
Views: 219
Reputation: 21743
You probably didnt look at the source code. Then you would have found out that there is a pretty option: https://github.com/cakephp/cakephp/blob/master/lib/Cake/Utility/Xml.php#L162
- `pretty` Returns formatted Xml when set to `true`. Defaults to `false`
Upvotes: 1