Grauw’s blog

XML Namespaces in IE

September 1st, 2006

A quick note about the namespaces support in IE; as the tests from my previous post show, it supports the namespaceURI and prefix properties (the latter is read-only though). But it does not support any of the *NS functions. This is really a problem if you want to dynamically modify XML namespaced documents.

However, it turns out that it does have some more to offer in the form of a couple of nonstandard methods and properties, which are sufficient to get the necessary functionality. It’s not ideal, but it will allow you to build some kind of compatibility layer. These are the respective methods:

With this method you can create nodes with a QName and namespace URI. This will allow you to support the functionality of createElementNS and createAttributeNS.
With this method you can get a namespaced item from a NamedNodeMap (read: attributes list). This corresponds to the getNamedItemNS functionality and can be used to implement hasAttributeNS, getAttributeNS, hasAttributeNodeNS and getAttributeNodeNS as well.
With this method you can remove a namespaced item from an attributes list. This corresponds to the removeNamedItemNS functionality, and can be used to implement removeAttributeNS.
Gets the element or attribute’s local name. This is the functional equivalent of the localName property.

In addition to these, functions like setAttributeNode are also (somewhat) namespace-aware in IE, so setAttributeNodeNS and setNamedItemNS are partially covered as well.

Finally, getElementsByTagNameNS can be implemented using getElementsByTagName('*') and the namespaceURI and baseName properties, or using IE’s selectNodes XPath implementation which would probably be faster.