开发者

How to do namespace aware DOM traversal in IE6..IE8 xml documents?

开发者 https://www.devze.com 2022-12-20 12:43 出处:网络
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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号