Here is my code with notes about the failures of XPath. How do I use XPath with the <sparql> XML document?:
======================================== // ==UserScript== // @name SparqlXMLDemo // @author Brooks // @date May 24, 2009 // @namespace http://www.ischool.washington.edu/ // @include * // @exclude http://faculty.washington.edu/tabrooks/ // ==/UserScript== (function() { try { var endpoint; var query; endpoint = "http://dbpedia.org/sparql"; query = "SELECT ?abstract WHERE { { <http://dbpedia.org/resource/ Civil_engineering> <http://dbpedia.org/property/abstract> ?abstract FILTER langMatches( lang(?abstract), 'en') } }"; ///////////////////////////////////////////////////////////// // HTTPRequest code GM_xmlhttpRequest({ method: 'GET', url: endpoint + '?query=' + query, headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Accept': 'application/sparql-results+xml,application/xml,text/ xml', }, onload: function(responseDetails) { /* ONE Use responseText to show document */ //alert(responseDetails.responseText); // Shows <sparql> XML document /* TWO Attempt to use XPath with responseText. Gives error: Error: uncaught exception: [Exception... "Could not convert JavaScript argument arg 1 [nsIDOMXPathEvaluator.evaluate]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///C:/Users/Terry/AppData/Roaming/Mozilla/Firefox/Profiles/ytgnjri7.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/components/greasemonkey.js :: anonymous :: line 365" data: no] */ //var allContent = responseDetails.responseText; //var headings = document.evaluate("//binding", allContent, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); //alert(headings.snapshotLength); /* THREE Attempt to use DOMParser. Gives error: Error: uncaught exception: [Exception... "Node cannot be used in a document other than the one in which it was created" code: "4" nsresult: "0x80530004 (NS_ERROR_DOM_WRONG_DOCUMENT_ERR)" location: "file:///C:/Users/Terry/AppData/Roaming/Mozilla/Firefox/Profiles/ ytgnjri7.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/ components/greasemonkey.js Line: 380"] */ //myXMLdocument = new DOMParser().parseFromString (responseDetails.responseText, 'text/xml'); //var headings = document.evaluate("//binding", myXMLdocument, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); //alert(headings.snapshotLength); } }); ////////////////////////////////////////////////////////////////// } catch (eErr) { alert ("Greasemonkey error: " + eErr); } return; }) (); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/greasemonkey-users?hl=en -~----------~----~----~----~------~----~------~--~---
