1. Rintze Zelle
  2. Scaffold
Issue #8 resolved

exemplar from HWZT ch11 produces no output

Tom Roche
created an issue

(see also this Zotero forum post http://forums.zotero.org/discussion/13316/scaffold-20-fails-to-run-examples-from-crymble-ch11/#Comment_65472 )

"How to Write a Zotero Translator" by Adam Crymble

http://niche-canada.org/member-projects/zotero-guide/chapter1.html

(aka HWZT) is still regarded as the best guide to writing a simple screenscraping translator for Zotero. Unfortunately

  • much has changed since HWZT was written, limiting its usability.
  • HWZT is not wikified, limiting its maintainability.

Hence I have started a wiki page

http://www.zotero.org/support/dev/how_to_write_a_zotero_translator_plusplus

to update it, e.g. by using uplevel tools. The examples in the first 10 chapters continue to work with minor alterations. However the examples in chapter 11 fail, and I don't see how to workaround. The first failing usecase is

0 in uplevel Firefox, install add-ons

and restart.

1 Open http://niche-canada.org/member-projects/zotero-guide/sample1.html in FF

2 Open Scaffold 2.0 (Tools>Scaffold) with that sample page open and focused.

3 in tab=Metadata, set Label=foo Creator=bar Target=http://niche-canada.org/member-projects/zotero-guide/

and hit button="Test Regex". Expected and actual results similar to

18:06:54 ===>true<===(boolean)

4 Switch to tab=Code and enter in the input text/frame (on the left) this code from Example 11.5 with a bit appended from Example 11.6 in http://niche-canada.org/member-projects/zotero-guide/chapter11.html

{{{

!javascript

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); } Zotero.debug(myXPathObject); }}}

then hit icon="Run doWeb" (the stylized thunderbolt). Expected result: text in the output text/frame (on the right) similar to

{{{

!quote

http://niche-canada.org/member-projects/zotero-guide/chapter11.html

myXPathObject is now equivalent to a Simple Variable holding, in this case, "Title: " }}}

Observed result: nothing.

Note that hitting icon="Run detectWeb" (the eye next to the thunderbolt) also produces no output.

Comments (3)

  1. Rintze Zelle repo owner

    I tested your code snippet, and found two things missing/wrong:

    1. The Zotero.debug command is outside the scope of detectWeb
    2. You haven't appended ".iterateNext().textContent;" to the XPath evaluation

    Finally, the function is detectWeb, so you have to press the Run detectWeb button in 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);
    }
    

    gives

    "07:02:43 Title:"

  2. Log in to comment