detectWeb did not match
Hi
I'm trying to build a translator for www.retsinformation.dk (an official site with all Danish legislation). This is my first go at writing a translator, so I'm going through https://www.zotero.org/support/dev/how_to_write_a_zotero_translator_plusplus. However, it starts to get complicated in ch. 11, and I can't get example 11.6 to work.
I've copy-pasted the following snippet from the guide into Scaffold:
function detectWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == "x" ) return namespace; else return null;
} : null;
var myXPath = '//td[1]';
var myXPathObject =
doc.evaluate(myXPath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
Zotero.debug(myXPathObject);
}
and the result I get is "detectWeb did not match". What's going wrong?
I'm trying to build a translator for www.retsinformation.dk (an official site with all Danish legislation). This is my first go at writing a translator, so I'm going through https://www.zotero.org/support/dev/how_to_write_a_zotero_translator_plusplus. However, it starts to get complicated in ch. 11, and I can't get example 11.6 to work.
I've copy-pasted the following snippet from the guide into Scaffold:
function detectWeb(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == "x" ) return namespace; else return null;
} : null;
var myXPath = '//td[1]';
var myXPathObject =
doc.evaluate(myXPath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
Zotero.debug(myXPathObject);
}
and the result I get is "detectWeb did not match". What's going wrong?
note that there are simpler ways of doing a lot of this now. You may actually be better off looking at some of the documentation at
https://www.zotero.org/support/dev/translators/coding
Specifically, for almost all purposes you can replace doc.evaluate and the whole namespace mess with the the much simpler
ZU.xpath() and ZU.xpathText(). In your example, e.g.
function detectWeb(doc, url){
var myXPath = '//td[1]';
var myXPathText = ZU.xpathText(doc, myXPath);
Z.debug(myXPathText);
}
I did indeed get the debug output first - somehow I managed to overlook that.
Thank for the link too, that will certainly be useful for me.