user440096
user440096

Reputation:

Adding linebreaks to XML generated by a PHP script

I've generated an XML file via PHP. However, the XML has been generated all on one line, with no linebreaks or indentation.

How can I make it so that each link in the XML file appears on a separate line? Here's the code I'm currently using:

$xml = new SimpleXmlElement('<links></links>');
$xml->addChild('dvd');

foreach ($articleList as $art) {
    $value = htmlentities($art->getAttribute('href'));
    $xml->addChild('alink', $value);
}

$xml->asXML('/simplexml_create.xml');

Upvotes: 0

Views: 419

Answers (1)

cetver
cetver

Reputation: 11829

beautify xml file is a bad idea, because in 1 line it's takes less disk space.
use xml formatting only for debugging purposes, this tool helps you - http://xmlbeautifier.com/default.aspx
see this question: Format output of $SimpleXML->asXML();
in Opera browser 1 line xml displays with formatting

Upvotes: 1

Related Questions