#38538 [NEW]: loadHTML doesn't use XHTML namespace
| From: | spam02 at pornel dot net | Date: | Mon, 21 Aug 2006 23:25:35 +0000 |
| Subject: | #38538 [NEW]: loadHTML doesn't use XHTML namespace | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-101080@lists.php.net to get a copy of this message | ||
From: spam02 at pornel dot net
Operating system: *
PHP version: 6CVS-2006-08-21 (snap)
PHP Bug Type: DOM XML related
Bug description: loadHTML doesn't use XHTML namespace
Description:
------------
From W3C: XHTML/1.0 is a reformulation of HTML 4 in XML. The semantics of
HTML and XHTML elements are identical.
loadHTML() should put loaded elements in XHTML namespace to preserve their
semantics. These aren't just any random elements - these are HTML elements,
and HTML elements in XML (therefore DOM) are in
"http://www.w3.org/1999/xhtml" namespace.
This isn't purely academic problem.
It's difficult to handle both HTML and XHTML uniformly using DOM in PHP -
difference in namespaces causes xpath/XSLT to behave differently.
AFAIK there's no trivial method of changing namespace of all document
elements, so namespace returned by loadHTML() is quite important.
SUGGESTED CHANGE
Simply putting elements in a namespace will break backwards-compatibility
a little (xpath queries for example). Therefore I suggest adding optional
boolean argument to loadHTML() and loadHTMLFile() that enables new
behavior.
Reproduce code:
---------------
<?php
$html = new DOMDocument(); $html->loadHTML('<html><body>hello');
$xhtml = new DOMDocument(); $xhtml->loadXML('<html
xmlns="http://www.w3.org/1999/xhtml"><body>hello</body></html>');
function test($doc)
{
$x = new DOMXPath($doc);
$x->registerNamespace("x","http://www.w3.org/1999/xhtml");
echo $x->evaluate("string(//x:body)");
}
test($html);
test($xhtml);
// local-name() could be used as workaround in this practicular text-case,
however this isn't possible/feasible in every case.
Expected result:
----------------
hellohello
Actual result:
--------------
hello
--
Edit bug report at http://bugs.php.net/?id=38538&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38538&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38538&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38538&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38538&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=38538&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38538&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38538&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38538&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38538&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38538&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=38538&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=38538&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38538&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38538&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38538&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38538&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38538&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38538&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38538&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38538&r=mysqlcfg