HWZT chapter 11 (XPath containers):
Again, a few changes since HWZT, and again, using its first Scaffold example as an example:
http://niche-canada.org/member-projects/zotero-guide/
Click on the "Detect Code" tab
, click on tab=Code.
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);
}
12:00:00 Title:
The code for the second complete Scaffold example (from “Example 11.10”) is similarly
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 = '//div[@id="Content"]/div/table[@class="Bibrec"]/tbody/tr/td[1][@class="Label"]';
var myXPathObject = doc.evaluate(myXPath, doc, nsResolver, XPathResult.ANY_TYPE, null);
var items = new Object();
var headers;
while (headers = myXPathObject.iterateNext()) {
items[headers.textContent]='';
}
Zotero.debug(items);
}
Click on icon=“Run detectWeb” (the eye): you should get results like
12:00:00 'Title:' => "" 'PrincipalAuthor:' => "" 'Imprint:' => "" 'Subjects:' => "" '' => "" 'ISBN-10:' => "" 'Collection:' => "" 'Pages:' => ""