createNSResolver and namespaced XPath
Howdy all. First and foremost, thanks a ton for 6638: http://bugzilla.opendarwin.org/show_bug.cgi?id=6638 I'm working on some XForms inspired stuff. 6638 is important for the ideas I'm trying out. I also saw 8791: http://bugzilla.opendarwin.org/show_bug.cgi?id=8791 ...and I'm sticking to createNSResolver for now. However, I can't get it to work with namespaced XPath expressions. For example the following matches nothing: <html> <head> <title>XPath Resolver in WebKit</title> <script> function search (xpath) { var xmlString = '<xf:model xmlns:xf="http://foo.org/"/>'; // Make a doc and a resolver var doc = (new DOMParser()).parseFromString(xmlString, "text/xml"); var contextNode = doc.documentElement; var nsResolver = document.createNSResolver(contextNode); // Evaluate a namespaced xpath var result = doc.evaluate('//xf:model', doc, nsResolver, null, null); alert(result.iterateNext().tagName); } </script> </head> <body> <h1>XPath resolver in WebKit</h1> <p>This page test the XPath .evaluate function in WebKit, in particular, looking up XPath expressions in foreign namespaces with <code>createNSResolver</code>.</p> <p><button onclick="search('//*');">Test</button></p> </body> </html> This test case is also at the following URL: http://zeapartners.org/~paul/xpathresolver.html It works in Firefox, giving "xf:model" as the alert, but "null" in a nightly WebKit (from yesterday). I certainly expect that I'm doing something wrong... Thanks for the help! --Paul
20 maj 2006 kl. 22.01 skrev Paul Everitt:
Howdy all. First and foremost, thanks a ton for 6638:
http://bugzilla.opendarwin.org/show_bug.cgi?id=6638
I'm working on some XForms inspired stuff. 6638 is important for the ideas I'm trying out.
I also saw 8791:
http://bugzilla.opendarwin.org/show_bug.cgi?id=8791
...and I'm sticking to createNSResolver for now. However, I can't get it to work with namespaced XPath expressions. For example the following matches nothing:
[test case snipped] This is a great test case that indeed shows a bug. Could you file a new bug and attach it? Regards, Anders
Anders Carlsson wrote:
20 maj 2006 kl. 22.01 skrev Paul Everitt:
Howdy all. First and foremost, thanks a ton for 6638:
http://bugzilla.opendarwin.org/show_bug.cgi?id=6638
I'm working on some XForms inspired stuff. 6638 is important for the ideas I'm trying out.
I also saw 8791:
http://bugzilla.opendarwin.org/show_bug.cgi?id=8791
...and I'm sticking to createNSResolver for now. However, I can't get it to work with namespaced XPath expressions. For example the following matches nothing:
[test case snipped]
This is a great test case that indeed shows a bug. Could you file a new bug and attach it?
Hi Anders, thanks for the fast reply. Here is the bug and attachment: http://bugzilla.opendarwin.org/show_bug.cgi?id=9035 http://bugzilla.opendarwin.org/attachment.cgi?id=8457 I grep'd through the WebKit source looking for JS tests that might show how to do an XPath selection of content in a namespace, but couldn't find anything. Do you have an example of something that works? Perhaps I was just doing it the wrong way. --Paul
participants (2)
-
Anders Carlsson
-
Paul Everitt