php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38083 encoding lost when using loadXML
Submitted: 2006-07-12 17:14 UTC Modified: 2006-07-14 06:25 UTC
From: john dot enevoldson at pulsen dot se Assigned: rrichards (profile)
Status: Not a bug Package: DOM XML related
PHP Version: 5.1.4 OS: SLES 9.3 64 bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: john dot enevoldson at pulsen dot se
New email:
PHP Version: OS:

 

 [2006-07-12 17:14 UTC] john dot enevoldson at pulsen dot se
Description:
------------
Encoding attribute is lost when using loadXML following a create new DOMDocument.



Reproduce code:
---------------
$doc3 = new DOMDocument('1.0','iso-8859-1');
$doc3->loadXML('<root></root>');
print $doc3->saveXML();


Expected result:
----------------
<?xml version="1.0" encoding="iso-8859-1"?>
<root/>


Actual result:
--------------
<?xml version="1.0"?>
<root/>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-14 06:25 UTC] chregu@php.net
The encoding of the loaded XML (which is utf-8 in your case) 
overwrites the one specified in "new DOMDocument" and that's 
expected behaviour.

use instead:

$doc3 = new DOMDocument('1.0');
$doc3->loadXML('<root></root>');
$doc3->encoding = 'iso-8859-1';      
print $doc3->saveXML();

and it works as you want
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC