===== Chapter 11: XPath containers ===== [[http://niche-canada.org/member-projects/zotero-guide/chapter11.html|HWZT chapter 11 (XPath containers)]]: Again, a few changes since HWZT, and again, using its first Scaffold example as an example: - Close any running Scaffold 2.0 instances. - Ensure the [[http://niche-canada.org/member-projects/zotero-guide/sample1.html|first sample page]] is open in your browser and has focus. - Open Scaffold 2.0 from the Firefox main menu with Tools>Scaffold. This should popup dialog="Zotero Scaffold". - If you are not already in tab=Metadata, select that. Enter some text in the Label and Creator fields. - The URI of the sample page has changed since HWZT, so you will need to enter Target=http://niche-canada.org/member-projects/zotero-guide/ - Hit button="Test Regex". You should get a result, in the "Test Frame" on the right of the tab, similar to that described in HWZT. - Instead of Click on the "Detect Code" tab, click on tab=Code. - In that tab enter 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); } - Click on icon="Run detectWeb" (the eye): you should get results like 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:' => "" **Next**: [[dev/How to Write a Zotero Translator, 2nd Edition/Chapter 12|Chapter 12: Regular Expressions]]