XML DOM, XPath and XMLHttpRequest support for O::U::SpiderMonkey
[Evergreen.git] / Open-ILS / src / javascript / backend / test / xmlhttprequest-test.js
1 // suck in what we need
2 perl_print('------------------------------LOAD---------------------------------------');
3 load_lib('xmlhttprequest.js');
4
5 perl_print('------------------------------START---------------------------------------');
6
7 perl_print("recordID is",params.recordID);
8
9 // xpath namespace resolver
10 var ns_res = new XPathNamespaceResolver(
11         { marc : "http://www.loc.gov/MARC21/slim",
12           mods : "http://www.loc.gov/mods/v3" }
13 );
14
15 // xmlhttprequest uses the perl xml parser to get the xml doc from 
16 var x = new XMLHttpRequest();
17 x.open('POST','http://dev.gapines.org/restgateway');
18 x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
19 x.send('service=open-ils.storage&method=open-ils.storage.direct.biblio.record_entry.retrieve&param=' + params.recordID);
20
21
22 // use the DOM to parse the marc record
23 var marc = DOMImplementation.parseString(x.responseXML.evaluate('//marc/text()').singleNodeValue.data);
24
25
26
27 // and then get the title
28 var res = marc.evaluate(
29         "/marc:record/marc:datafield[@tag='245']/marc:subfield[@code='a']/text()",
30         marc,
31         ns_res
32 );
33
34 // print the title we just grabbed
35 perl_print(res.singleNodeValue.data);
36
37 perl_print('------------------------------END---------------------------------------');
38