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?
This is an old discussion that has not been active in a long time. Before commenting here, you should strongly consider starting a new discussion instead. If you think the content of this discussion is still relevant, you can link to it from your new discussion.
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.