php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41800 XMLWriter - invalid XML output
Submitted: 2007-06-25 13:08 UTC Modified: 2007-08-23 14:04 UTC
From: a dot anpilogov at gmail dot com Assigned:
Status: Not a bug Package: XML Writer
PHP Version: 5.2.3 OS: FreeBSD
Private report: No CVE-ID: None
 [2007-06-25 13:08 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-25 16:29 UTC] 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-26 11:56 UTC] pajoye@php.net
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).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC