tags:

views:

61

answers:

2

Hi,

Having an .html file is it possible to force the browser to treat the contents as XHTML? I mean the file opened from both local or web location. Maybe some on-the-fly convertion or something like that?

The background:

Firefox and Opera supports natively MathML when the code is embedded in a XHTML file. I need to get a .html file with MathML that would be supported by the mentioned browsers properly.

Thank you for any support.

A: 

For local files (see below if you are using a server):

Browsers generally only run off file extensions for determining if a local file is HTML or XHTML.

Your options:

  • Rename the files
  • Run a local webserver that can serve with an application/xhtml+xml content type
  • Wait for HTML 5 support of inline SVG
  • Use JS to generate the SVG
  • Use symbolic links (if you are on *NIX) so you have both file names available
  • Add a Doctype detection and parse mode switching feature to Firefox, it is open source (yes, I realize this isn't the most practical suggestion, that is why it is last)

For files served via HTTP:

Consult the manual to find out how to change the content type for a given file extension. For example, Apache can use the AddType directive.

David Dorward
A: 

File extension has nothing to do in this case. The only thing that really matters is the Content-Type header. By default your webserver treat .html files, as text/html, but you should force it to send is as application/xhtml+xml.

If you're using any server-side language, you can do something like that (PHP example)

header('Content-Type: application/xhtml+xml');

If you're unable to use any programming language, then you can configure your webserver to treat .html files as XHTML (Apache, .htaccess example)

AddType application/xhtml+xml .html

Edit:

I didn't noticed that you're also trying to open XHTML from local file. Then file extension may be important - but David Dorward answer to that case.

Crozin
application/xhtml+xml, not application/xml+xhtml
Alohci
Thanks! Corrected.
Crozin