php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49266 DOMDocument::loadHTMLFile add default Namespace even if it already exists
Submitted: 2009-08-15 12:52 UTC Modified: 2010-04-08 11:13 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: gmblar+php at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.0 OS: MacOSX 10.5.8
Private report: No CVE-ID: None
 [2009-08-15 12:52 UTC] gmblar+php at gmail dot com
Description:
------------
DOMDocument::loadHTMLFile add default Namespace even if it already 
exists

Reproduce code:
---------------
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>DOM-Test</title>
	</head>
	<body>
		<p>Hello World</p>
	</body>
</html>


<?php

header('Content-Type: text/plain');
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->loadHTMLFile('test.html');
echo $dom->saveXML();

?>

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 
/>
    <title>DOM-Test</title>
  </head>
  <body>
    <p>Hello World</p>
  </body>
</html>


Actual result:
--------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" 
/>
    <title>DOM-Test</title>
  </head>
  <body>
    <p>Hello World</p>
  </body>
</html>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-08 11:13 UTC] rrichards@php.net
-Status: Open +Status: Bogus
 [2010-04-08 11:13 UTC] rrichards@php.net
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

You are mixing HTML functions (non namespace aware) when loading with XMl 
functions (which are namespace aware) when saving. Load it via XML functions since 
its xhtml. HTMl functionality is present for convenience only as DOM is meant for 
XMl functionality
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 30 04:01:23 2020 UTC