#41800 [Opn->Bgs]: XMLWriter - invalid XML output

From: Date: Tue, 26 Jun 2007 11:56:49 +0000
Subject: #41800 [Opn->Bgs]: XMLWriter - invalid XML output
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114269@lists.php.net to get a copy of this message
ID: 41800 Updated by: pajoye@php.net Reported By: a dot anpilogov at gmail dot com -Status: Open +Status: Bogus Bug Type: *XML functions Operating System: FreeBSD PHP Version: 5.2.3 New Comment: libxml does not check the validity of the encoding inside a text or CDATA while creating them. Unicode support in php will solve this issue as it detects badly encoded data. But in the meantime, you have to use alternative solutions like the iconv the mb strings function. Not a (php) bug (bogus). Previous Comments: ------------------------------------------------------------------------ [2007-06-25 16:29:15] a dot anpilogov at gmail dot com <?php $xw = new XMLWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'UTF-8'); $xw->writeElement('root', "\x04\xA0"); $xw->endDocument(); header('Content-type: application/xml'); print $xw->outputMemory(true); ?> Output will be an invalid XML. Another example: <?php $xw = new XMLWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'ISO-8559-1'); $xw->writeElement('root', "\x04\xA0"); $xw->endDocument(); header('Content-type: application/xml'); print $xw->outputMemory(true); ?> Warning: XMLWriter::startDocument() [function.XMLWriter-startDocument]: xmlTextWriterStartDocument : out of memory! ------------------------------------------------------------------------ [2007-06-25 13:08:10] a dot anpilogov at gmail dot com Description: ------------ It is possible to create invalid XML file using XMLwriter. In my case, the first symbol of Unicode text was 00 13, and XMLWriter just put it out, so I had to call preg_replace('/^.{1}/us', '', $str) to make valid UTF-8 string, than pass it to XMLWriter. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41800&edit=1

« previous php.bugs (#114269) next »