views:

311

answers:

9

I just tried viewing my website http://www.logmytime.de/ in Opera (version 10.50) it gives me an "xml parsing failed error" and refuses to display the web page.

I can choose to "Reparse the document as HTML" and then the page works fine, but that's hardly a solution to my problem.

The weird thing is that the error still occurs after setting a HTML (instead of XTHML) doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd"&gt;

I checked the source output from the browser to make sure I did not make any mistake with the Doctype I even viewed the same web page in Firebug and it shows a Content-Type of text/html; .

So, why does Opera still try to parse my web page as XML?

Thanks,

Adrian

Edit: Just to clarify: I am not asking what the error on my web page is. I understand why this is not valid XHTML. However, I am also using the javascript micro templating engine, and it's templates are never valid XML, which is why I need the browser to parse my entire web site as HTML, not XHTML. In order to demonstrate this, I just inserted an example template into the web page.

<script type="text/html" id="StopWatchTemplate" > 

<h1><a href="#" onclick="TimeEntriesList.EditTimeEntry('<#=timeEntryID#>')"><#=currentlyRunning?"Aktueller":"Letzter"#> Stoppuhr-Zeiteintrag</a></h1>
<%-- Stoppuhr - Ende--%>

</script>

When opening the page in Opera, you can see that the template now produces XML parsing errors even though the doctype for the page is still HTML.

Edit 2:: Just to make this even clearer: I am not asking why my web page is not valid XHTML. I am asking why Opera tries to parse it as XHTML despite of the HTML doctype.

A: 

Try from another PC to make sure that you're not hitting a cache issue.

Chris Thornton
I tried it from another computer, but the problem still persists.
Adrian Grigore
+6  A: 

You have the "class" attribute specified two times.

alt text

From Well-formedness constraint: Unique Att Spec:

An attribute name MUST NOT appear more than once in the same start-tag or empty-element tag.

Developer Art
-1: Thanks for your reply, but you are not answering my question. Please see my edit above.
Adrian Grigore
Regarding your question: "Why would you possibly want to intentionally produce invalid documents?": Please see my edit above.
Adrian Grigore
@Adrian Grigore: this *does* answer your question. It's simple: the specification *forbids* browsers to display broken documents. Period. If you want your document displayed, fix it. Also, you write: "I checked the source output from the browser to make sure **I did not make any mistake** ". Clearly, you didn't check very carefully, since you missed this one.
Jörg W Mittag
A: 

The page code is cached in your browser, which is why you are continuing to see the error. You originally saw the error, because your code is likely not valid.

I tried it from another computer, but the problem still persists.
Adrian Grigore
+10  A: 

Your document is not a valid HTML document. So, the browser should reject it. Unfortunately, due to a historic accident, most browsers do not reject invalid documents, but rather try to fix them (usually with pretty crappy results), so that the authro never even notices that his document is broken.

Thankfully, with XHTML, the browser vendors decided to fix that, and actually reject invalid documents. In your case, you are delivering your document as XHTML with the application/xhtml+xml MIME type:

# curl --head http://www.logmytime.de/
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 12529
Content-Type: application/xhtml+xml; charset=utf-8
              ^^^^^^^^^^^^^^^^^^^^^
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 2.0
X-AspNet-Version: 2.0.50727
Set-Cookie: Referrer=None; path=/
X-Powered-By: ASP.NET
Date: Tue, 04 May 2010 16:08:40 GMT
So, the browser rejects your document (as it should). When you switch over to HTML, then it tries to fix your broken HTML.

Now, you have changed your DOCTYPE to HTML 4.01, but you are still delivering it as XHTML. All you have achieved now is that there are two reasons for the browser to reject your document: it's still invalid because you haven't fixed the actual bug and the DOCTYPE and the MIME type don't match up.

Instead of mucking around with DOCTYPEs and MIME types in order to get the browser to parse your broken document, the correct way to solve this problem would be to simply fix the invalid markup and remove the extraneous class attribute on line 172. [BTW: who wrote that document? The indentation and formatting is awful.]

Jörg W Mittag
+1 for stealing my answer. The document looks auto-generated to me, but that is a little weird considering ASP.NET MVC doesn't generate the page code for you. He's probably using third-party controls or something that generates HTML code automatically.
iconiK
-1: Sorry, but you are not answering my question. There is a good reason why I would want to use non-xhtml code. Please see my edit above.
Adrian Grigore
@Adrian, he did answer your question. The web serving tells the browser your page is `application/xhtml+xml`, the proper doctype for XHTML, which causes it to enter XML parsing mode. But you tell it nothing in the page, apart from the doctype, which is ignored because of the MIME type. As your page's markup is **TOTALLY BROKEN**, the browser raises an XML parsing error.
iconiK
That curl log shows that your server is sending the page as XHTML
AlfonsoML
@Adrian Grigore: First off, if you want to use non-XHTML, then why are you serving it as `application/xhtml+xml`? And secondly, it doesn't have anything to do with XHTML. Your document is invalid *HTML*, anyway. It doesn't matter whether you interpret it as XHTML or HTML, because it is *neither*.
Jörg W Mittag
In that case I guess my question is "Why is the web server sending the page as XHTML?"
Adrian Grigore
Jörg: I am using the javascript micro templating engine, that's why my page can never be valid XHTML, even if I do fix the other obvious errors. See the example template in my edit1 above.
Adrian Grigore
@Adrian Grigore: This might be relevant: http://stackoverflow.com/questions/2013224/response-contenttype-sporaticly-changes-for-ie8-using-asp-net-mvc
Developer Art
@Andrian, your web server is serving it as XHTML because that's how IIS is configured to do by default with any ASP.NET web page.
iconiK
+1  A: 

It seems like the server is serving a different mime types to different user-agents. Firefox is getting text/html but Opera (and curl according to Jörg W Mittag) is getting application/xhtml+xml. Do you have any content-negotiation code for your site?

Alohci
I have no code on my web page that looks for the browser type and returns different content-types to different browser versions. Or do you mean something else?
Adrian Grigore
http://stackoverflow.com/questions/2013224/response-contenttype-sporaticly-changes-for-ie8-using-asp-net-mvc
Developer Art
+3  A: 

The web server is configured to server your page as application/xhtml+xml, which is the proper doctype for XHTML markup. When any browser gets that, it will enter XML parsing mode. As you do not specify a different MIME type in the page via a <meta> tag, the browser assumes your page is XHTML (hence XML) and will happily ignore your HTML 4.01 Transitional doctype; since your page's markup is severely broken, it will encounter many XML errors and complain.

It turns out Opera is more strict than other browsers about what it accepts and will simply refuse to eat the garbage you are giving it (as in badly broken markup). Please fix your web page markup before you continue to comment here. The W3C validator is an invaluable tool for this; on your home page you have over 200 errors and nearly 2000 warnings.

iconiK
How exactly do you propose to fix the template quoted in the first edit in my post? It appears you have not understood that I am using the javascript microtemplating engine and therefore I cannot use pure XHTML.
Adrian Grigore
Also, even after adding the following meta tag, opera still tries to parse the site as XML: <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">.
Adrian Grigore
@Adrian Grigore: You need to specify content-type in response headers. In web.config or on a per-case basis in Response.ContentType.
Developer Art
@DeveloperArt: Thanks! That's exactly the answer I was looking for.
Adrian Grigore
@Adrian, I didn't ask you to make it pure XHTML. But surely, if a tool can't generate remotely valid HTML, it's a bunch of crap. Seriously, 200 errors and 10 times more warnings?
iconiK
If you'd bother reading what John Reisig's microtemplating engine does, you might be able to understand why your comment makes very little sense. But since you only seem to be interested in starting a flaming war, there is obviously very little hope.
Adrian Grigore
@Adrian, aside from reconfiguring the server to server the page as text/html, you can't do anything else to get Opera to show your page.
iconiK
+2  A: 

In case someone else has the same problem: As suggested by DeveloperArt it can be fixed with a simple ContentType="text/html" attribute in the page element.

Adrian Grigore
+2  A: 

You got the correct answer (HTTP content-type header mandating XML parsing) and it seems it's fixed. I'll just add a minor hint on how you can figure out what's wrong from within Opera itself. Two possible ways:

1) Info panel

This is not visible by default, but if you open the panel bar on the left (press F4 to toggle if you don't see it), then click the small plus sign at the bottom, you can enable "Info" in the menu.

The info panel shows some assorted information about the page currently open, including encoding and MIME type.

2) Opera Dragonfly

Press Ctrl-Shift-I to open developer tools (or go through menus to Tools > Advanced > Opera Dragonfly)

Go to "Network" tab, then re-load site. You will see the request and can review the headers. Comparing this with corresponding information from Firebug would have shown you the difference in Content-type headers. (Here you will also see that Opera sends an "Accept" header that contains "application/xhtml+xml". This means "Hi server, if you happen to have this file in real XHTML format I would understand that just fine.". Perhaps your server-side framework saw that header and wrongly responded with the XHTML content-type even though the content was invalid?)

hallvors
Thanks for the information on the developer tools and info panel. It should come in handy for further debugging.
Adrian Grigore
A: 

It is because you've kind of told it to...

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
Sohnee
I have considered this too, but it is not really relevant in this case. The problem is indeed that the server is sending a content type of application/xhtml+xml; to opera browsers by default and text/html to almost all other browsers. I'm still not sure why this is (I did not code anything browser-dependent on the server side), but at least I now know how to override it.
Adrian Grigore