Closed
Bug 561257
Opened 15 years ago
Closed 15 years ago
Way to get type of node from DOM
Categories
(Core :: General, enhancement)
Tracking
()
RESOLVED
INVALID
People
(Reporter: sroussey, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Build Identifier:
Need a way to find out of a node is HTML or XHTML (or SVG or MathML).
http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/5fe539085da72a64/5948aee3f6c79d34
Reproducible: Always
Comment 1•15 years ago
|
||
For an element, its "type" is completely determined by its namespace URI. There is no other concept of type for elements.
| Reporter | ||
Comment 2•15 years ago
|
||
XHTML and HTML document's nodes have the same namespace. So surely there is something else. ???
Comment 3•15 years ago
|
||
No, there is not. XHTMLness is attached to the document, not to individual elements. If you move an element from an XHTML document to an HTML one, or vice versa, you won't be able to tell that it didn't originally come from that document (where by "you" I mean "anyone in Gecko").
| Reporter | ||
Comment 4•15 years ago
|
||
And the way to tell if a document is HTML vs XHTML?
Comment 5•15 years ago
|
||
Depends on how you want to treat text/plain and the like, but here's one approach:
if (document.contentType == "text/html") {
// HTML
} else if (document.contentType == "application/xhtml+xml") {
// XHTML
} else {
// This could, of course be the same as the "XHTML" case but just parsed as
// XML so the document is not an HTMLDocument.
}
| Reporter | ||
Comment 6•15 years ago
|
||
But at:
http://www.microsoft.com/en/us/default.aspx
document.contentType == "text/html"
with the doctype of:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Comment 7•15 years ago
|
||
Right, because the doctype has absolutely nothing to do with how the page is treated by Gecko in terms of HTML vs XHTML. We treat that page as HTML, not XHTML.
Which is a good thing, since it's not actually well-formed XML. So if we treated it as XHTML, we would just show the "XML Parsing Error: not well-formed" yellow screen of death.
| Reporter | ||
Comment 8•15 years ago
|
||
In regards to XHTML pages with XHTML doctypes served as text/html:
"For the next version of Firebug, I've made the doctype visible in the HTML
view, and mark it red and with an error message (on hover) for sites that do
the above. Essentially, the browser ignores the XHTML references and obeys
the mime-type, and web page authors can go on for a while never knowing.
Microsoft.com, ibm.com, and developer.mozilla.org all now get flagged with
errors."
http://lists.w3.org/Archives/Public/public-html/2010Apr/1145.html
That is the message that got our conversation rolling. Others that stated that I was wrong to flag these sites, as they were not in error. (And thus that copying using Firebug to copy a BR node them should use <br /> instead of <br>).
"These conflict with the following:
http://www.w3.org/TR/xhtml1/#ref-xhtmlmime"
http://lists.w3.org/Archives/Public/public-html/2010Apr/1148.html
"The 'text/html' media type [RFC2854] is primarily for HTML, not for XHTML. In general, this media type is NOT suitable for XHTML. However, as [RFC2854] says, [XHTML1] defines a profile of use of XHTML which is compatible with HTML 4.01 and which may also be labeled as text/html."
http://www.w3.org/TR/2002/NOTE-xhtml-media-types-20020801/#text-html
"[XHTML1], Appendix C "HTML Compatibility Guidelines" summarizes design guidelines for authors who wish their XHTML documents to render on existing HTML user agents. The use of 'text/html' for XHTML SHOULD be limited for the purpose of rendering on existing HTML user agents, and SHOULD be limited to [XHTML1] documents which follow the HTML Compatibility Guidelines. In particular, 'text/html' is NOT suitable for XHTML Family document types that adds elements and attributes from foreign namespaces, such as XHTML+MathML [XHTML+MathML]."
http://www.w3.org/TR/2002/NOTE-xhtml-media-types-20020801/#text-html
"XHTML documents served as 'text/html' will not be processed as XML [XML10], e.g. well-formedness errors may not be detected by user agents. Also be aware that HTML rules will be applied for DOM and style sheets (see C.11 and C13 of [XHTML1] respectively)."
http://www.w3.org/TR/2002/NOTE-xhtml-media-types-20020801/#text-html
What I got from the above was that microsoft.com has a xhtml document as its home page. Previoously, I would have said that they have a badly formed html page.
| Reporter | ||
Comment 9•15 years ago
|
||
God, editing in these little boxes is awful... Reworked P2 above:
That is the message that got our conversation rolling. Others stated that
I was wrong to flag these sites, as they were not in error. (And thus, for example, using Firebug to copy a BR node should use <br /> instead of
<br>).
Comment 10•15 years ago
|
||
> Others that stated that I was wrong to flag these sites, as they were not in
> error.
OK.
> thus that copying using Firebug to copy a BR node them should use <br />
> instead of <br>
Why, exactly? In any case, it must be for a reason unrelated to how Gecko perceives the documents, since all those documents are HTML as far as Gecko is concerned....
> What I got from the above was that microsoft.com has a xhtml document as its
> home page.
It's a matter of definition, I guess. What they have is a document that is neither valid XHTML nor valid HTML, nor is it well-formed XML.
Appendix C says that given an XHTML document that satisfies certain constraints it can be sent as text/html. But the Microsoft document is not an XHTML document (in the sense of validating as XHTML; there's really not much other sense to it in practice).
I guess maybe we need to back up to the actual problem statement. Is this all about the copy issue?
Comment 11•15 years ago
|
||
And by the way, in trunk Firefox the textarea is resizable... ;)
| Reporter | ||
Comment 12•15 years ago
|
||
Well, it is a matter of perception. If you look at developer.mozilla.com in firebug, what should it do?
Marking a mismatch between the doctype and contentType no longer seems viable.
http://code.google.com/p/fbug/issues/detail?id=2548
Copying nodes could go either way. Should it depend on what the user thinks it is? Or what mode Gecko is in?
http://code.google.com/p/fbug/issues/detail?id=3030
Assuming the best, that is, that an XHTML document is served as text/html and conforms to Appendix C, how should Firebug relay that to the user?
If I have an About subtab and the document is selected, and it says:
Mode: Quirks/Standards
Type: HTML/XHTML
What should the type be???
Comment 13•15 years ago
|
||
> If you look at developer.mozilla.com in firebug, what should it do?
In what sense? What is firebug trying to achieve?
> Should it depend on what the user thinks it is? Or what mode Gecko is in?
Probably depends on where you plan to paste them.... which isn't very helpful, I know.
> What should the type be???
Why does anyone care what the type is? If I understood that, I might be better able to answer the question...
Comment 14•15 years ago
|
||
(In reply to comment #12)
> Assuming the best, that is, that an XHTML document is served as text/html and
> conforms to Appendix C, how should Firebug relay that to the user?
I suggest treating Appendix C as obsolete and not trying to relay to the user things about it. (Appendix C has never been normative.)
Comment 15•15 years ago
|
||
So this is invalid/incomplete, as far as I understand.
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → INVALID
Comment 16•15 years ago
|
||
FWIW, in Firefox 3.6 or later, to check if a document has the HTMLness bit set, you can do
var htmlnessBitSet = (document.createElementNS("http://www.w3.org/1999/xhtml", "div").tagName == "DIV");
| Reporter | ||
Comment 17•15 years ago
|
||
Thanks Henri, indeed Firebug checks the case of tagName to make these determinations. Your way seems more fullproof, but I'd have to cache the result and check that instead of checking the case of individual tags.
Ref: http://code.google.com/p/fbug/issues/detail?id=3049
You need to log in
before you can comment on or make changes to this bug.
Description
•