[Webkit-unassigned] [Bug 14835] createElement(x) vs. createElementNS(null, x)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jan 7 01:30:14 PST 2010


https://bugs.webkit.org/show_bug.cgi?id=14835


Maciej Stachowiak <mjs at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




--- Comment #4 from Maciej Stachowiak <mjs at apple.com>  2010-01-07 01:30:11 PST ---
(In reply to comment #0)
> The behavior of createElement and createElementNS is confusing. 
> 
> 1. createElement() creates elements with the xml namespace
> "http://www.w3.org/1999/xhtml" even though neither IE or Fx has that behavior.  

This is the standard behavior according to HTML5, for HTML documents. If you
call createElement() on an XML document, you'll get the null namespace. This
change is because in HTML5, HTML elements in HTML documents are now in the
XHTML namespace instead of in the null namespace, for consistency.

> 2. createElementNS() behaves differently if the first argument is null or
> undefined. I think there is an incorrect string conversion occurring in the
> underlying code. 

Technically, only strings or the null value are allowed for the namespace
argument, and null is treated the same as the empty string. Anything else is
converted to string, and thus the undefined value turns into the string
"undefined". So this is also correct.

> 
> Consider the following examples:
> 
> $ var d = window.document.implementation.createDocument("", "", null);
> $ d.appendChild(d.createElement("foo"));
> $ (new XMLSerializer()).serializeToString(d);
> = <foo xmlns="http://www.w3.org/1999/xhtml"></foo>
> $ (new XMLSerializer()).serializeToString(e.evaluate("//foo",
> d.documentElement, null, null, null).iterateNext());
> = 
> 
> $ var d = window.document.implementation.createDocument("", "", null);
> $ d.appendChild(d.createElementNS(null, "foo"));
> $ (new XMLSerializer()).serializeToString(d);
> = <foo/>
> $ (new XMLSerializer()).serializeToString(e.evaluate("//foo",
> d.documentElement, null, null, null).iterateNext());
> = <foo/>
> 
> $ var d = window.document.implementation.createDocument("", "", null);
> $ d.appendChild(d.createElementNS(window.undef, "foo"));
> $ (new XMLSerializer()).serializeToString(d);
> = <foo xmlns="undefined"/>
> $ (new XMLSerializer()).serializeToString(e.evaluate("//foo",
> d.documentElement, null, null, null).iterateNext());
> =

All of this is correct behavior per spec, assuming you do it in an HTML
document.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list