I am implementing a javascript library that talks to a SOAP webservice. I use the XMLHttpRequest to do requests and receive responses. The SOAP responses rely heavily on multiple namespaces.
For all major browsers, except all versions of Internet Explorer, I can use getElementsByTagNameNS()
and getAttributeNS()
to traverse and parse the response. But not in Internet Explorer.
Now, I have read some documentation (http://msdn.microsoft.com/en-us/library/ms756048(VS.85).aspx) which indicates how you actually can use namespace aware XPath if you first set the SelectionNamespace
property of the DOM document. This only works if you know both the namespace uris you want to take into account (which is reasonable) as well as the namespace prefixes that the document happens to use.
This last requirement seems completely unreasonable - how am I supposed to know what namespace prefixes happen to be used? I first thought that I could traverse the document entirely and keep track of all namespaces and prefixes, but the problem is that the prefix/uri association is not fixed for the document as a whole, any element may redefine those associations anywhere in the document. Another approach that I thought of is to search all ancestors of the context node to discover which prefix/namespace combinations are in effect for that node prior to evaluating my XPath expression, and I think this would work if I can guarantee that all XPath expressions are executed serially and not in parallel.
Is there a better way? What are people using to do namespace aware DOM traversal in IE?