#38483 [Asn->Bgs]: DOM fragments ignore document encoding

From: Date: Thu, 17 Aug 2006 14:41:28 +0000
Subject: #38483 [Asn->Bgs]: DOM fragments ignore document encoding
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-100909@lists.php.net to get a copy of this message
ID: 38483 Updated by: rrichards@php.net Reported By: webmaster at bison-soft dot de -Status: Assigned +Status: Bogus Bug Type: DOM XML related Operating System: linux 2.4 PHP Version: 5.1.4 Assigned To: rrichards New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php string passed to appendXML() must be utf-8 encoded and doc is not mixed - loadxml() creates a new document defaulting to utf-8 encoding since you do not have an xml decl. Previous Comments: ------------------------------------------------------------------------ [2006-08-17 14:04:26] webmaster at bison-soft dot de Description: ------------ An XML-String appended to a DOMDocumentFragment with appendXML() must always be encoded with UTF-8, regardless of the choosen DOMDocument encoding. Even worse, after appending the fragment to the document, the charset in the fragment remains UTF-8, which leads to a DOMDocument with mixed encodings inside. Reproduce code: --------------- $dom = new DOMDocument('1.0','ISO-8859-1'); $dom->loadXML('<parent />'); $frag = $dom->createDocumentFragment(); $frag->appendXML('<child>öäü</child>'); $dom->documentElement->appendChild($frag); Expected result: ---------------- the ISO-8859-1 encoded XML-String will cleanly import into the document fragment. Actual result: -------------- Error: DOMDocumentFragment::appendXML() Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !! When trying to use an XML-declaration containing the ISO-8859-1 encoding in the child-XML-String: Entity: line 1: parser error : XML declaration allowed only at the start of the document When you convert the child-XML-String to utf8 and append it, you have a DOMDocument with mixed charset ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38483&edit=1

« previous php.bugs (#100909) next »