Closed Bug 437589 Opened 16 years ago Closed 14 years ago

Element.tagName should always be UPPERCASE in HTML DOM

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: sjoerdmulder, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0

According to your own documentation: http://developer.mozilla.org/en/docs/DOM:element.tagName in HTML the tagName property should always be uppercase, but if you import a document from XML the tagName property is still lowercase.
Example:

alert(document.importNode(new DOMParser().parseFromString('<div xmlns="http://www.w3.org/1999/xhtml">Test</div>', 'text/xml').documentElement, true).tagName); => 'div'

Reproducible: Always

Steps to Reproduce:
1.
2.
3.
You should read the documentation more closely.  It also says:
"In XML (and XML-based languages such as XHTML), tagName preserves case."

By parsing it as text/xml, you're telling it the document is XML, maybe XHTML.  XML and XHTML are case-sensitive, too.
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
Maybe you should read the documentation more closely, by using document.importNode you are cloning the document into an HTML document and "In HTML, tagName returns the element name in the canonical uppercase form.".
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
All right, let's break this down.  I do see your point, but I am not quite convinced.

var docSrc = '<div xmlns="http://www.w3.org/1999/xhtml">Test</div>';
var doc = new DOMParser().parseFromString(docSrc, 'text/xml');
var element = document.importNode(doc.documentElement, true);
alert(element.tagName);

The problem is as I said before - the element is XML before it is HTML.  Yes, XHTML is a combination of XML and HTML, but in the XHTML case it's still case-sensitive.

If I'm wrong, I'm sure one of the DOM peers will tell me, but I'm not one to resolve a bug invalid twice.  I'll let someone else judge that.
Thank you :) Safari, does actually return uppercase tagName, Opera also doesnt. 

Ofcourse this can be simply fixed in JS by always doing elm.tagName.toUpperCase(), but i think the HTML DOM tagName getter should do that ;-)
You could also take this testcase a step further, importing the element from the HTML document (after this transformation) into a second XML document.  What should the second imported element's tagName be then?

If it's "DIV", then it's not a XHTML element anymore - it's an element undefined in the XHTML namespace.  If it's "div", then how would it fit the original testcase?
You also should consider that the original element might have other attributes on it.  If the original element was instead:

<div xmlns="http://www.w3.org/1999/xhtml" xml:id="myDiv">Test</div>

would the xml:id attribute, including namespace, be preserved in the HTML document and in the second XML document?  HTML doesn't have XML namespaces.  XHTML does, and the DOM would behave differently in both cases (DOM Level 1 versus DOM Level 2)...
Component: DOM: HTML → DOM: Core & HTML
Fixed by the changes to match the HTML5 spec on this (and in particular by the switch to keying off namespace only to determine "html-ness").
Status: UNCONFIRMED → RESOLVED
Closed: 16 years ago14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.