You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Konstantin Preißer <kp...@apache.org> on 2015/08/10 20:24:04 UTC

[OT] RE: Tomcat 8 jspx and HTML5

Hi Christopher,

> -----Original Message-----
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Sent: Sunday, August 9, 2015 4:33 PM
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
> 
> Konstantin,
(...)
> > I read it so that when using HTML syntax (text/html), you cannot
> > omit the end element of a <script> tag. Section 8.1.2 (Elements)
> > [2] also doesn't seem to allow a self-closing tag for <script>
> > elements.
> 
> Agreed. My experience is that even when using application/xhtml+xml,
> the browser still demands that both parts of the tag appear. It's been
> a while since I've bothered re-investigating the situation, since it's
> just easier to standardize on <script><!-- --></script> and have it
> work everywhere.

At least for current version of Safari and for the versions of Firefox and Chrome that have been available for about 3 years, and IE >= 9, I have checked that they correctly interpret "application/xhtml+xml" as XML syntax. Only IE 8 and below will display an download dialog to the user.


> > However, you can use the XML syntax instead the HTML syntax for
> > serializing HTML5, which means using a Content-Type of
> > "application/xhtml+xml". When using this content type, a browser
> > supporting HTML5 (including IE 9+) will use an XML parser, so a
> > syntax like <script /> will work on such documents.
> 
> True, but older browsers are usually not compliant. Our application
> needs to support some stinky older browsers, so we unfortunately have
> to support the lowest common denominator (like usual with the web).

I agree. Fortunately, support for IE 8 (on Win Vista and Win7) will finally be dropped on January 12, 2016 [1]. However IE 9 will still be supported until 4/11/2017 for Win Vista (and 1/14/2020 for Win Server 2008).


> > (The problem with XML syntax however is that there are some
> > JavaScript libraries that don't seem to be aware that there's an
> > XML syntax of HTML5 and will not work correctly, e.g. jQuery Mobile
> > up to version 1.4.5.)
> 
> I wasn't aware of that; I was under the impression that jQuery
> operated on the DOM tree which has already been parsed by the browser.

Note that it is jQuery Mobile that had the problems whereas jQuery generally works correctly on XHTML documents.
jQuery Mobile uses jQuery to allow to build webapps with a look & feel optimized for mobile devices.

jQuery allows to easily manipulate the DOM, and to generate new DOM elements, there are several methods, for example:

A)
$("<div>", { style: "color: red;" }).append(
   $("<span>", { id: "test1" }).text("Hi a&b<c>")
)

B)
$('<div style="color: red;"><span id="test2">Hi a&amp;b&lt;c&gt;</div>')

A) will use the DOM interface (e.g. document.createElement) to create the elements, so it is independently from the underlying document syntax (HTML or XHTML/XML) (and you could insert nodes into the DOM that would not be possible to write in HTML/XHTML syntax).
B) mostly uses the element.innerHtml property, for which the syntax depends on the type of the document (HTML or XHTML/XML) that included the script. B) has a missing "</span>" which will work on HTML, but throw a syntax error on XHTML documents.

jQM until version 1.4.5 had some of these bugs, e.g. 'this.element[ 0 ].tagName === "TEXTAREA"' [2] which did not work on XHTML because it is case-sensitive (and the element names are defined lower-case) and setting 'tmp.innerHTML = "<div class='ui-slider'>"' [3] which threw an exception on XHTML as the end-tag is missing.
(I reported those bugs as I use this library in a project at work, but there are some other JS libraries which have similar problems on XHTML and I did not have time to report/investigate them, so I had to switch back from XHTML to HTML syntax there.)

Also, e.g. Google Translator still does not work with XHTML because it strips quotes from attribute values when outputting the translated result (<div a=b>  instead of <div a="b">) which fails to parse in browsers when using the XHTML content type.

(I would guess that because XHTML is not used very often, people often forget to think about it when writing code/libraries dealing with HTML code or to test it with XHTML documents, even though the XHTML syntax is part of the HTML5 spec [4] [5] instead of being a separate specification like it was for "XHTML 1.0" vs "HTML 4.01" some years ago.)


Regards,
Konstantin Preißer


[1] https://support.microsoft.com/en-us/gp/msl-ie-dotnet-an
[2] https://github.com/jquery/jquery-mobile/issues/7959
[3] https://github.com/jquery/jquery-mobile/issues/7849
[4] http://www.w3.org/TR/html5/introduction.html#html-vs-xhtml
[5] http://www.w3.org/TR/html5/the-xhtml-syntax.html#the-xhtml-syntax


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org