detectWeb did not match


I'm trying to build a translator for (an official site with all Danish legislation). This is my first go at writing a translator, so I'm going through 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;

and the result I get is "detectWeb did not match". What's going wrong?
  • You would get a does not match message with this, that's correct (in technical terms, it's a function that doesn't return anything). Are you not getting the debug output (i.e. the content of //td[1]) displayed before it?

    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
    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);
  • Thanks for the answer.

    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.
Sign In or Register to comment.