Correct content type for html use? - content-type

I was using XHTML on my website but that completely destroyed jQuery and its plugins.
Therefore, I want to go back to html 4. I am defining some custom attributes for my html, like so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd" [
<!ATTLIST mytag myattribute CDATA #IMPLIED>
]>
This seems to be valid html for, but when I pass such a page from my server with a content type of text/html, my browser displays ']>' - it can't parse the doctype properly.
Is there a different content type I should be using?

From A List Apart
If you run such a file through the W3C validator, you find that it
validates wonderfully well. If you download the sample files for this
article and validate file internal.html, you can see this for
yourself. Unfortunately, when you display the file in a browser, the
]> shows up on the screen. There’s no way around this bug, so this
approach is right out.
So this basically isnt going to work. To get it to work you need to copy the DTD you want the server/local machine, edit it appropriately and put it in a publically accessible place. See the article for more detail.
As far as jQuery is concerned, it should work fine if you quit trying to customize the DTD in the fashion that you are. Im not sure about using a custom DTD as I have never done it, but just adding the attributes to the elements and not defining them in the DTD shouldnt cause a problem with jq. Granted the document wont validate, but validation is just a tool and not overly important in the grand scheme of things.

Related

SonarQube rule - "title" should be present in all pages

The rule "title" should be present in all pages is present on the Web Profile of SonarQube. I understand the reason why it exists but I am facing a situation where nothing can be done - so far - to avoid its violation. Let me explain...
When developing using primefaces if the header in xhtml is declared as just "head" tag it does not include some artificats that belongs to the primefaces framework. So, a xhtml like is required
<h:head>
<title>something</title>
....
<h:/head>
But this violates the rule I mentioned in bold.
Maybe because it checks html and xhtml files... not sure.
My thought about that was:
to edit this rule so it would recognize as a complaint code a h:head, or;
change the extension files this rule scans, or;
as last case disable it;
Any ideas about what to do and how to do it?

Is there any HTML 5 construct that is ONLY supported in the XML serialization?

Does there exist any "thing"(element, DOM manipulation, styling, nesting of elements, attributes, anything of that sort...) one can do in XHTML 5, that one CANNOT do in HTML 5? I remember reading on the web about one such case, but I cannot recall where it is I saw it.
This is apart from the use of content from external namespaces such as SVG and MathML (which is supported in HTML as well).
For reference, the number of answers to the converse question "what can you do in HTML 5 that you can't in XHTML 5?" are very large, given the strictness of XHTML. Hence I'm looking for answers to this question.
Yes, for example entity declarations and references to entities so defined. They are part of XML, so they must be supported when using XML serialization, as it is required to follow generic XML rules. Example:
<!DOCTYPE html [
<!ENTITY foo "Hello world">
]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
</head>
<body>
&foo;
</body>
</html>
XHTML, being XML supports xml-stylesheet declarations. Not just CSS but also XSLT. Which can transform the document tree before presentationXSLT also supports inclusions via document("foo.xml"), which can be used as an XInclude surrogate since no browser supports the latter right now.
XML parsers validate well-formedness
XHTML supports namespaces, allowing other XML content (not just SVG and MathML) to be embedded
CDATA sections
.innerHTML, .insertAdjacentHTML() and .createContextualFragment() validate well-formedness
The topic is quite interesting in general. E.g. an XHTML5 parser is not quite the same as a pure XML parser, as the HTML5 spec mandates a few willful violations of the XML parser, e.g. to support the <template> element.
There also are a handful of states in which you can have a valid DOM that will throw an error if you try to export it through the XHTML fragment serialization algorithm.
And the HTML Fragment serialization algorithm may emit a string which will result in a different DOM when parsed again by a HTML parser.
So basically all three of the following are not fully isomorphic to one another, in any combination:
the XHTML5 serialization
the (X)HTML5 DOM
the HTML5 serialization.
In XHTML, you can use self-closing syntax (/>) on non-void elements:
<script src="js.js" />
And void elements can have stray end tags:
<input></input>
I was able to find what I was remembering vaguely in this unofficial Q&A by hsivonen. I'm still looking for other such "features".
[...] In this case, you must avoid constructs that aren’t supported in text/html (e.g. div as a child of p).
Searching about more, I found this page (second post from top) :
but basically a p can never enclose a div in HTML (or XHTML served with the mime type text/html). If you are serving XHTML with an XML mime type, you can do this in theory, but the result would not be valid XHTML.
saying that the HTML parser simply doesn't allow the possibility, while the XHTML parser, which doesn't need to second-guess the code, accepts it but it's still invalid.
I decided to test it out : took an application/xhtml+xml page, tried to add a div inside a p using Chrome dev tools "Edit as HTML" function. It worked. I copied the source, made the same change and tested it in validator.nu. It marked it as invalid, to my slight disappointment.
Trying to add a div in a text/html page in the same manner was impossible. As soon as I exited the "Edit as HTML" mode, it simply moved the div after the p.

Classic ASP page automatically sets Quriks mode as default in IE 8

While viewing the HTML IE 8 sets the default document mode as IE8 Standards as it should but it enters quirks mode on an asp page.
Even if I use <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
it doesn't really help.
What should I do?
First thing I would do would be place identical output in a HTM file and visit that instead. If you get different results then there really is something wierd going on because I doubt IE8 has any way to treat "asp" any differently.
BTW, How do you know its actually going into quirksmode?
What happens if you use stronger DTD like this:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Does it still remain in quirksmode?
You're not confusing IE7 compatibility with Quirksmode are you?
IE7 had a number of bugs in how it render even Standards mode HTML, perhaps what are seeing is IE7 compatibility instead.
Use fiddler to examine the headers being sent with the content. Is there a header like this:-
X-UA-Compatible: IE=EmulateIE7
in the response?
Is the Compatibility button present next to address in the brower UI?
The only thing that actually works is <meta http-equiv="X-UA-Compatible" content="IE=8"/>, other browsers will ignore it but IE will be forced to be in IE-8 mode unless you've done something really stupid like putting something before the HTML.
I write standards based classic ASP all the time. The things to check would be your HTTP headers. Make sure something isn't being inserted into your HTTP header to cause it to use quirks mode. Might check your IIS box to make sure there isn't something being sent in the "Custom HTTP Headers" section in IIS. Also, check that your doctype is indeed correct. Lastly, make sure that you do not have any of IE's special meta tags that can change the rendering mode. Just because classic ASP is old doesn't mean that the browser would display it any different than any other HTML page. Honestly the browser doesn't really even care what the extension is. If it is served as html mime type then it will render as such.

Rendering XHTML as MS Word Document - Headers

I generate an XHTML document and set the Mime type as "application/msword" so it opens in Word.
To create a header I appear to have to reference an external file thus:
<style>
...
#page{mso-footnote-separator:url("**OUT_files/header.htm**") fs;
mso-footnote-continuation-separator:url("OUT_files/header.htm") fcs;
mso-endnote-separator:url("OUT_files/header.htm") es;
mso-endnote-continuation-separator:url("OUT_files/header.htm") ecs;}
#page Section1{
mso-header-margin:.5in;
mso-header:url("OUT_files/header.htm") h1;
} }
...
</style>
Does anyone know how to reference a div defined within the main XHTML document itself, without having to reference an external file?
Thanks
MS Word is quite locked down. I was not able to get this to work with a non-external file, but it seems to make sense. The values being "included" are repeated in the display. It's not possible to have "hidden" divs and refer to them (at least, not when I was trying), so not sure how to get this to work properly.
For me, I ended up just creating a simple Macro that would handle this for me.
If you are very lucky, a data: URL might work, maybe, in Word 2007? I haven't tried that myself, but MS introduced partial support for data: URLs in IE8.

What are the best practices for using HTML with XML based languages like SVG?

From browsing on this site and elsewhere, I've learned that serving websites as XHTML at present is considered harmful.
Delivering XHTML and serving it as application/xhtml+xml isn't supported by the majority of people browsing at present, delivering xhtml as text/html is at best a placebo for myself, and at worst a recipe for breaking sites usually when you least need it happening.
So we end up back at html 4.01. If I instead serve my pages as html 4.01, is it possible to use SVG or any other XML-based language on the page?
If so, how?
In HTML you won't be able to insert SVG directly.
You can embed SVG files with <object>/<embed> and in cutting-edge browsers (Opera, Safari) also <img> and CSS background-image.
You can put SVG in data: URI to avoid using external files.
Simple mathematical expressions can be written with help of Unicode and basic HTML/CSS (Opera 9.5 supports large chunk of MathML via CSS). For anything more complex you'll need to use images, like Wikipedia does.
HTML misinterprets namespace prefixes, so you won't be able to (properly) use other XML markup with HTML DOM. HTML5 has data-* attributes for application-specific markup additions. For metadata consider Microformats.
However if you want to embed XML only for non-browsers (robots), then you could use HTML-compatible XHTML subset and HTTP content negotiation to send proper XML with proper type to clients that understand it (if you thoroughly test page in both XML and HTML modes, then it won't be harmful).
You may (read I haven't tried this myself) to use an embedded object and type it accordingly.

Resources