Search code examples
htmlxhtmloperadoctype

Why does Opera parse my web page as XML?


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">

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 the HTML doctype.

Edit3:: Please do not post any more answers, I have found the cause of this and documented it below.


Solution

  • 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.

    Edit: The problem was in fact caused by a bug with the mobile.Browser file I am using in my web project. The workaround above works, but it is not really necessary in my case. See this answer for more details.