views:

170

answers:

1

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?

A: 

They are probably regex munging the namespaces out before traversal.

If standards based xml parsing in client script is what you are after, you might get some mileage out of XML4Script. It needs an unobtrusive overhaul but if you can deal with the noise in the window it might help.

Sky Sanders
There is also Sarissa (http://dev.abiss.gr/sarissa) which ive used before... not really by choice and i dont know that id recommend it per se, but it works.
prodigitalson
Thanks to you both! Looking at the footprint of these solutions, I think I will try to wing it until I really can't avoid this anymore. Hopefully IE will finally support namespaces by that time </optimism>
Roland Bouman
your welcome. @son- sarissa slipped my mind. it is current, fairly well covered with tests, clean and uses underlying implmenetations when available. would be a good choice.
Sky Sanders