Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » xpath
xpath [message #530802] Sat, 01 May 2010 06:34 Go to next message
Filip is currently offline FilipFriend
Messages: 16
Registered: March 2010
Location: Czech Republic
Junior Member
Hello, I have a problem with using xpath function "matches". I guess
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_IDOMXPATHEVA LUATOR_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;
}

[Updated on: Sat, 01 May 2010 06:34]

Report message to a moderator

Re: xpath [message #531328 is a reply to message #530802] Tue, 04 May 2010 14:38 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Your post on the mozilla newsgroup is more likely to be seen by someone
that's familiar with this. For anyone that's interested the link is
http://groups.google.com/group/mozilla.dev.embedding/browse_ thread/thread/fa23a0634d881ba7# .

Grant


"Filip" <filip.pekarek@gmail.com> wrote in message
news:hrgi0r$gp2$1@build.eclipse.org...
> Hello, I have a problem with using xpath function "matches". I guess
> 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_IDOMXPATHEVA LUATOR_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;
> }
Previous Topic:Is it possible to use combo with cascade behavior ?
Next Topic:Redirecting Scroll Wheel Events
Goto Forum:
  


Current Time: Sat Apr 20 01:35:26 GMT 2024

Powered by FUDForum. Page generated in 0.02225 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top