views:

21

answers:

1

At W3schools an article on XML Namespaces states:

Note: The namespace URI is not used by the parser to look up information

I have a very simple XML file:

<?xml version="1.0" encoding="utf-8"?>
<foo> 
    <bar>Hi!</bar>
    <button xmlns="http://www.w3.org/1999/xhtml"&gt;Click Me!</button>
</foo> 

Opening this file in Chrome or Firefox displays an HTML button (not in IE). Does this mean some browsers process XMLNS? Is this one of those "extra/nice" features provide by browsers for the common XHTML namespace?

Just curious!

+1  A: 

The first thing to note is that you should be careful before relying on W3Schools for information — a lot of what is there is bogus, or poorly explained.

Concerning your specific question: most modern browsers will take namespaces into account. They are able to recognise languages that they support (such as XHTML or SVG) that way, as you have noticed. Note however that this happens when the browser knows that it is processing XML, so you have to make sure that that is the case, for instance by using an XML media type (application/xml, text/xml, and naturally application/xhtml+xml or image/svg+xml).

You don't indicate which version of IE you tested with. There are ways of getting older versions of IE to process namespaces in interesting ways, but they tend to be hacky. IE9 should be able to handle it correctly.

Robin Berjon