0

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');
1
  • Try opening your XML file in a browser like Chrome or Firefox. Usually they have some built-in XML node explorer that will make things a bit prettier to look at. Commented Oct 8, 2011 at 21:13

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ok i understand your point. But I still want it more readable while i develop the xml file as it will become a lot more complicated and I'll need to beable to quickly reference how its looking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.