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');
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • 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. – Bailey Parker Oct 08 '11 at 21:13

1 Answers1

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

Community
  • 1
  • 1
cetver
  • 11,279
  • 5
  • 36
  • 56
  • 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. –  Oct 08 '11 at 23:47