Add refine search form
[mp-xquery-moved-to-github.git] / src / tst.cpp
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <assert.h>
5
6 #include <zorba/zorba.h>
7 #include <zorba/store_manager.h>
8 #include <zorba/serializer.h>
9 #include <zorba/singleton_item_sequence.h>
10 #include <zorba/zorba_exception.h>
11
12
13 using namespace zorba;
14
15 bool
16 example_1(Zorba* aZorba)
17 {
18     XQuery_t lQuery = aZorba->compileQuery("1+2");
19
20     std::cout << lQuery << std::endl;
21
22     return true;
23 }
24
25 bool
26 example_2(Zorba* aZorba)
27 {
28     XQuery_t lQuery = aZorba->createQuery();
29     std::string path( "/home/adam/proj/marc2bibframe/xbin/zorba3-0.xqy");
30
31     std::unique_ptr<std::istream> qfile;
32
33     qfile.reset( new std::ifstream( path.c_str() ) );
34
35     Zorba_CompilerHints lHints;
36
37     // lQuery->setFileName("http://base/");
38     lQuery->setFileName("/home/adam/proj/marc2bibframe/xbin/");
39
40     lQuery->compile(*qfile, lHints);
41
42     zorba::DynamicContext* lDynamicContext = lQuery->getDynamicContext();
43
44     zorba::Item lItem = aZorba->getItemFactory()->createString("http://base/");
45     lDynamicContext->setVariable("baseuri", lItem);
46
47     lItem = aZorba->getItemFactory()->createString(
48         "/home/adam/proj/yaz/test/marc6.xml");
49     lDynamicContext->setVariable("marcxmluri", lItem);
50
51     lItem = aZorba->getItemFactory()->createString("rdfxml");
52     lDynamicContext->setVariable("serialization", lItem);
53
54     std::cout << lQuery << std::endl;
55
56     lItem = aZorba->getItemFactory()->createString(
57         "/home/adam/proj/yaz/test/marc7.xml");
58     lDynamicContext->setVariable("marcxmluri", lItem);
59
60     std::stringstream ss;
61
62     lQuery->execute(ss);
63
64     std::string result = ss.str();
65
66     std::cout << result << std::endl;
67
68     return true;
69 }
70
71 int main(int argc, char **argv)
72 {
73     void* lStore = StoreManager::getStore();
74     Zorba *lZorba = Zorba::getInstance(lStore);
75
76     assert(lZorba);
77
78     example_1(lZorba);
79
80     example_2(lZorba);
81
82     lZorba->shutdown();
83     StoreManager::shutdownStore(lStore);
84     return 0;
85 }
86 /*
87  * Local variables:
88  * c-basic-offset: 4
89  * c-file-style: "Stroustrup"
90  * indent-tabs-mode: nil
91  * End:
92  * vim: shiftwidth=4 tabstop=8 expandtab
93  */
94