I'm trying to add new line in a CData node with XMLWriter in PHP.
$xml = new XMLWriter();
$xml->openURI('php://output');
$xml->startDocument('1.0', 'UTF-8');
$xml->setIndent(true);
$str = "my string\nmy string";
$xml->startElement('test');
$xml->writeCData($str);
$xml->endElement();
$xml->endDocument();
But the output doesn't return any new line as I wrote "\n"...
returns :
<test>my string my string</test>
instead of :
<test>my string
my string
</test>
I saw on other posts that some users use the "& #10;" code or "& #xD;" (without space) but when I put it in my $str variable, thoses characters are escaped and XMLWriter writes it as output, and doesn't make a new line.
Do you have some ideas ?
Thank you very much !
I believe there are no easy ways of formatting the output of PHP's XMLWriter as the output is intended to be machine readable, not human readable. It might be possible to use XMLWriter::writeRaw to add custom line breaks though.