Closed Bug 393340 Opened 17 years ago Closed 15 years ago

createElementNS without namespace in HTML document creates a broken element

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: jruderman, Unassigned)

Details

(Keywords: testcase)

Attachments

(2 files)

Attached file testcase
The following script in an HTML document: var newHR = document.createElementNS(hr.namespaceURI, hr.tagName); creates an element that doesn't actually get displayed as an HR. It looks the same in DOM Inspector (same tagName, same lack of namespaceURI) but behaves differently. This breaks one method of serializing and reconstructing DOMs, where serializing means listing each element's namespaceURI and tagName and reconstructing means using document.createElementNS. I have to do special things for elements in HTML documents that don't have a namespace, and even that doesn't quite behave consistently.
Note that I don't really care *what* namespace HTML elements have (when they were created by the text/html parser). I just care about being able to use that namespace to construct new equivalent elements.
Actually, per current specs, we're doing the right thing. .namespaceURI on HTML elements (not XHTML) is null. And calling createElementNS with a null namespace will create just a plain element, not a HTML one.
Where do you see that? http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-2141741547 looks to me like it's saying that createElementNS with namespace null should be equivalent to createElement.
Actually, according the the spec they are definitly different. createElement creates nodes with a null localName, createElementNS creates nodes with a non-null localName. However we don't follow the spec on that and always create nodes with non-null localName. A problem is that if we let htmlDoc.createElementNS('foo', null) creates a HTML element, there is no way to use a htmlDoc to create plain XML elements in the null namespace. FWIW, the HTML5 spec says that HTML elements should have the xhtml namespace. But that is a bit weird too since then your call would create an XHTML element rather than a HTML one.
> But that is a bit weird too since then your call would create an XHTML element > rather than a HTML one. Will there be a difference?
XHTML and HTML elements are different yes. The simplest difference is that one is case sensitive and one is not. But there are also a bunch of web-compat-quirks that we apply to HTML elements that we don't on XHTML elements.
Ugh. Is there some way for me to tell whether an element is an "HTML element" rather than an element that happens to have a null namespace but is not an HTML element?
foo instanceof Components.interfaces.nsIDOMHTMLElement?
myElement instanceof HTMLElement
Using createElementNS with the XHTML ns URI works for me even when the DOM is in the HTML mode.
This testcase works now, thanks to the fix for bug 468708. The original one doesn't because tagName is uppercase.
That makes me happy.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → WONTFIX
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: