php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62259 Additional xml declaration added to document when calling save
Submitted: 2012-06-08 06:08 UTC Modified: 2013-12-03 09:56 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: andreas dot a dot sandberg at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.13 OS: Ubuntu
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: andreas dot a dot sandberg at gmail dot com
New email:
PHP Version: OS:

 

 [2012-06-08 06:08 UTC] andreas dot a dot sandberg at gmail dot com
Description:
------------
It appears an extra xml declaration can get added as part of the output when 
calling saveXML on a DOMDocument that was loaded by calling loadHTML.  Not sure 
how common of a use case this is but I load by xhtml doc using the loadHTML call 
as it is more forgiving and the content I'm loading already has the xml 
declaration.  Of course I can remove it but not sure if this is the intended 
behavior. 

Test script:
---------------
$xml = '<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html><head></head><body></body></html>';

$dom = new DOMDocument();
$dom->loadHTML($xml);
$out = $dom->saveXML(null);

echo $out;



Expected result:
----------------
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html><head/><body/></html>


Actual result:
--------------
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<?xml version="1.0" encoding="utf-8" standalone="no"??>
<html><head/><body/></html>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-03 09:56 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-12-03 09:56 UTC] mike@php.net
loadHTML loads HTML4.

XHTML must be valid XML, so you have to load it with loadXML.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 18:01:30 2024 UTC