Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xpath function

15 views
Skip to first unread message

Filip Pekarek

unread,
Apr 29, 2010, 3:32:37 PM4/29/10
to
Hello, I have a problem with using xpath function "matches". I gues
it's the regexp problem, but I have tried almost everything. Calling
function "contains" works fine, but calling "matches" throws
org.mozilla.xpcom.XPCOMException: The function "evaluate" returned an
error condition (0x805b0033). I cant find detail of the exception
enywhere.
I am using xulrunner-sdk-1.9.1.3-win32. Are all functions from
http://www.w3.org/2005/xpath-functions supported?
When you call "xpath.evaluate" with "expr" in the snippet below, it
works, but using "expr2" throws exception.
Any ideas?
Thanks for reply.

Here's my snippet

public class XPath {

static Browser browser;

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2, true));
shell.setText("Use Mozilla's Design Mode");
try {
browser = new Browser(shell, SWT.MOZILLA);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " +
e.getMessage());
return;
}
browser.setLayoutData(new GridData(GridData.FILL,
GridData.FILL, true, true, 2, 1));
Button searchButton = new Button(shell, SWT.PUSH);
searchButton.setText("Search");
searchButton.addListener(SWT.Selection, new Listener() {

public void handleEvent(Event event) {
search();
}
});
browser.setJavascriptEnabled(false);
browser.setUrl("http://www.google.com");
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

public static boolean search() {
nsIWebBrowser webBrowser = (nsIWebBrowser)
browser.getWebBrowser();
if (webBrowser == null) {
System.out.println("Could not get the nsIWebBrowser from
the Browser widget");
return false;
}
nsIDOMWindow window = webBrowser.getContentDOMWindow();
nsIDOMDocument document = window.getDocument();
nsIDOMXPathEvaluator xpath = (nsIDOMXPathEvaluator)
document.queryInterface(nsIDOMXPathEvaluator.NS_IDOMXPATHEVALUATOR_IID);
nsIDOMXPathNSResolver res = xpath.createNSResolver(document);
res.lookupNamespaceURI("http://www.w3.org/2005/xpath-
functions");
String expr = "//input[contains(@name,'q')]";
String expr2 = "//input[matches(@name,\"[q]{1}\")]";
nsISupports obj = xpath.evaluate(expr2,
document,
res,

nsIDOMXPathResult.UNORDERED_NODE_ITERATOR_TYPE,
null);
nsIDOMXPathResult result = (nsIDOMXPathResult)
obj.queryInterface(nsIDOMXPathResult.NS_IDOMXPATHRESULT_IID);
nsIDOMNode node;
int i = 0;
while((node = result.iterateNext()) != null) {
System.out.println(node.getNodeName());
System.out.println(i++);
}

return true;
}
}

0 new messages