html:title in pure XML document - html

I decided to use pure XML+CSS instead of (X)HTML for my webpage.
I use and with no problems.
However I can't specify webpage's title.
Document looks like this:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="style.css"?>
<html:html xmlns:html="http://www.w3.org/1999/xhtml">
<html:head>
<html:title>FooBar</html:title>
</html:head>
<site>
<header>foo</header>
<article>
<title>foo</title>
<p>foo bar <html:a href="#">foobar</html:a></p>
</article>
</site>
</html:html>
But it doesn't work.
Update: it works on Chrome and Internet Explorer. Doesn't work on Firefox.

Why don't you leave xhtml as it is and use another namespace with an alias for your custom tags?
Edit
I mean something like:-
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:a="urn:mycrop.com:mystuff">
<head>
<title>FooBar</title>
</head>
<a:site>
<a:header>foo</a:header>
<a:article>
<a:title>foo</a:title>
<p>foo bar foobar</p>
</a:article>
</a:site>
</html>
Of course this will fail if the browser strictly expects XHTML but that was true of your originally anyway.
From your comments elsewhere in this question it looks like you've gone for XSLT as a stylesheet anyway. That being the case you needn't bother with including any of the HTML stuff anyway, just have the source XML contain the data you want to display.

OK, I used XSLT to do this. Works like a charm on every browser.

Related

What do I need to put at the top of my HTML?

I have the following at the top of my document:
<html class="js" lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
Can someone tell me if I need the xmlns part? I am not 100% sure but I think this is
doing some things to my tags. For example when I look at the tag is see the
following with firebug:
element.style {
height: 100%;
}
If I just have this as at the top of my code then I don't see the element.style ..
<html class="js" lang="en">
Just to give some background. I'm developing an MVC application for use with English. It uses HTML5 things in a few places.
For the current html spec, (which is html5) you will not need any fancy attributes, the following is adequate:
<!DOCTYPE html>
<html>
<head>
<title>Html page</title>
</head>
<body>
<p>This is an example Html page.</p>
</body>
</html>
Also, if you are not using the html5 spec, you should.
If you are using HTML5, then the extra tags probably should not be there as they are not needed any longer.. HTML5 uses a much cleaner syntax. :)
Here is the W3 documentation about this
You do not need to give those attributes in the tag.
<html>
</html>
will work fine even in HTML5 or HTML 4.01
The xmlns attribute may be needed if the document will be processed by XML tools that do not necessarily use HTML namespace as the default. You can see this by saving the document locally and opening it in Firefox; if the xmlns attribute is missing, Firefox will display the document source, just with XML syntax coloring, because it treats all tags just as pure markup with do meaning or default rendering rules.
If the document is served as HTML (Content-Type: text/html), then browsers will imply HTML semantics (HTML namespace).
Regarding the question you asked in the heading, you should put a doctype declaration, such as <!DOCTYPE html>, for all new documents. Otherwise you will trigger Quirks Mode, which means a large and undocumented set of oddities.

Displaying HTML from DB in <h:outputText escape="false"> results in broken HTML page

Is there any way to setup Firefox and Chrome to work with escape=false attribute in h:outputText tag. When there is some html that needs to be shown in the browser, Firefox and Chrome show parsed string correctly, but any other links in application are freezed (??).
The example html from db:
<HEAD>
<BASE href="http://"><META content="text/html; charset=utf-8" http-equiv=Content-Type>
<LINK rel=stylesheet type=text/css href=""><META name=GENERATOR content="MSHTML 9.00.8112.16434">
</HEAD>
<BODY><FONT color=#000000 size=2 face="Segoe UI">läuft nicht</FONT></BODY>
Parsed HTML on the page:
läuft nicht
What is very weird, is that in IE everything works (usually it is opposite).
I use primefaces components (v2.2), .xhtml, tomcat 7 and JSF 2.0
You end up with syntactically invalid HTML this way:
<html>
<head></head>
<body>
<head></head>
<body>...</body>
</body>
</html>
This is not right. There can be only one <head> and <body>. The browsers will behave unspecified. You need to remove the entire <head> and the wrapping <body> from that HTML so that you end up with only
<FONT color=#000000 size=2 face="Segoe UI">läuft nicht</FONT>
You'd need to either update the DB to remove unnecessary HTML, or to use Jsoup to parse this piece out on a per-request basis something like as follows:
String bodyContent = Jsoup.parse(htmlFromDB).body().html();
// ...
Alternatively, you could also display it inside a HTML <iframe> instead with help of a servlet. E.g.
<iframe src="htmlFromDBServlet?id=123"></iframe>
Unrelated to the concrete problem:
Storing HTML in a DB is a terrible design.
If the HTML originates from user-controlled input, you've a huge XSS attack hole this way.
The <font> tag is deprecated since 1998.
It seems to me that you're trying to do something that JSF was not really meant to do. Rather than try to insert HTML in your web page, you ought to try having the links already on your page and modifying the "rendered" attribute through an AJAX call.

XHTML empty tags not treated as empty tags by any browser

So I've tried this XHTML 1.1 code (validated at validator.w3.org) in Chrome 6, IE 8, and Firefox 3.5. The <p> following the <a/> gets hyperlinked, and the <p> following the <div/> turns red:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
</head>
<body>
<p><a href="http://www.yahoo.com"/></p>
<p>
this should not be hyperlinked
</p>
<div style="background:red"/>
<p>this should not be red</p>
</body>
</html>
This is really bad news for anyone trying to deal with documents using XML parsers/generators.
I might be able to just convert all </> tags to <></>, but that would mean that things like <br/> become <br></br> -- which is just weird, albeit valid.
Thoughts?
If you serve your document with an XML content-type (such as application/xhtml+xml) then you shouldn't have this problem.
It sounds like you are serving your document as text/html (although this isn't blessed by the text/html specification, which only goes up to XHTML 1.0) in which case you need to follow the HTML compatibility guidelines as you are telling browsers (and other user agents) that it is HTML rather than XHTML.
I might be able to just convert all </> tags to <></>, but that would mean that things like <br/> become <br></br> -- which is just weird, albeit valid.
… and wrong. Some browsers will treat that as <br><br>. Elements defined as EMPTY should use self-closing syntax, everything else should have explicit start and end tags.
Sadly, the simple option of using the correct content-type just introduces a different problem…
… although I believe this will be resolved when IE8 and lower lose significant market share as IE9 introduces support for XHTML.

Why is <div /> not treated the same as <div></div>

I was just testing this and in both IE8 & Chrome I see the same thing, empty (styled) divs are rendered differently depending which way you do it. It annoys me because the former seems so much neater.
Why?
EDIT: thanks for the clarifications on XHTML Vs HTML. Currently I have this:
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Test</title>
What is a better choice? I'd prefer XHTML as I believe it's a bit nicer.
In XHTML (served with Content-Type of application/xhtml+xml), <div /> would indeed work. But in HTML mode (text/html), then no; HTML is not XML, and XML empty tag syntax is not recognised.
<div /> is invalid markup. Since a div can't be self closing (it would just render an empty div), some browsers might render it differently. The HTML 4.01 specs state that divs (and spans) have to have both a start and end tag.
Also take a look at this question.
XHTML and HTML work differently.
In XHTML the 2 are identical and are semantically no different.
In plain HTML, you cannot self close tags. And making your tags self close is not bad, it just doesn't make a difference. The self closures are ignored.
So in plain HTML <div/> is seen as <div> which is never closed. So you need the </div> to close the tag.
HTML browsers have a hardcoded list of self closing tags and handle it for you.

Non-standard tag behavior in Opera

I'm working with a publishing system that uses custom tags. These are interpreted on the server. The problem is, that they cause big problems with Opera, when viewed locally (custom tags are not interpreted).
Opera is handling these tags differently from other browser. It looks like it is closing the tag at the end of the document (even if the tag contains closing slash). I'm just wondering, if such behavior is considered bug or feature.
Also, if you have any idea how to hack such code so that I can debug HTML+CSS for Opera locally (without interpreted custom tags), please let me know. Thank you.
Try the folowing code to see it in action (live example):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Non-standard tag behavior in Opera</title>
<style type="text/css" media="all">
div { background: yellow; padding: 1em; }
nonstandardtag { border: 1px solid red; }
</style>
</head>
<body>
<div>
<nonstandardtag>content of non-standard tag</nonstandardtag>
main tag content
</div>
<div>
<nonstandardtag />
main tag content
</div>
</body>
</html>
I use opera for more than 5 years. It is the browser that approaches the standard the best. Most of the sites that look bad in Opera are "optimized" for IE.
But an obvious question is, why do you need to use nonstandard tags? You can use the div and span tags for almost any nonstandard solution.
Short: it's not a bug. Despite the DOCTYPE, your page is not interpreted as XHTML (and this is intentional).
HTML simply doesn't support the self-closing tag syntax the same way as XML.
In HTML, in practice <foo /> is the same as <foo> or <foo /="">. In theory it's same as <foo></foo>>.
You need to tell browser to interpret page as X[HT]ML. DOCTYPE is not enough. To do this locally, file has to have .xml or .xhtml extension. When you serve file over HTTP, you must set Content-Type header to application/xhtml+xml or similar XML type (for static files usually .xhtml file extension does the job).
Your live example is served as text/html, so it won't be interpreted as XHTML, and won't work as you expect.
BTW: XHTML doesn't allow non-standard elements. If you want to add your own elements anyway, you should at least use your own namespace.
This seems to be fixed in Opera 10. So I guess it was not a feature.
One, you don't need non-standard elements. Two, whatever you claim with your doctype, this isn't XHTML but HTML (as you make clear with the <meta http-equiv="Content-Type" content="text/html…. That obviously means that browsers use their HTML parsers, and those don't (and shouldn't) support XML's shorthand syntax <element/> for empty elements.
Short answer: there are no guarentees or requirements on what a User Agent may do if you feed it malformed data.