2
* Copyright 2006-2012 The FLWOR Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
using org.zorbaxquery.api;
21
namespace ZorbaApplication
25
static string test(string query, string xml, string doc) {
26
InMemoryStore store = InMemoryStore.getInstance();
27
Zorba zorba = Zorba.getInstance(store);
29
XmlDataManager dataManager = zorba.getXmlDataManager();
30
Iterator docIter = dataManager.parseXML(xml);
32
Item idoc = new Item();
37
DocumentManager docManager = dataManager.getDocumentManager();
38
docManager.put(doc, idoc);
40
XQuery xquery = zorba.compileQuery(query);
41
string result = xquery.execute();
47
InMemoryStore.shutdown(store);
52
static string readFile(string file) {
53
System.Text.StringBuilder sb = new System.Text.StringBuilder();
54
using (StreamReader sr = File.OpenText(file)) {
56
while ( (line = sr.ReadLine()) != null) {
63
static bool compareStrings(string a, string b) {
64
string[] aMult = a.Split('\n');
65
string[] bMult = b.Split('\n');
66
if (aMult.Length > bMult.Length) {
70
foreach (string line in aMult) {
71
if (line.Equals(bMult[i++])) {
78
static void Main(string[] args)
80
System.Console.WriteLine("Running: XQuery execute - parsing XML");
82
string xml = readFile("books.xml");
83
string doc = "my_fake_books.xml";
84
string query = "doc('my_fake_books.xml')";
85
string testResult=readFile("test07.result");;
86
System.Console.WriteLine("XML: " + xml);
87
System.Console.WriteLine("Query: " + query);
91
result = test(query, xml, doc);
92
} catch(Exception e) {
93
System.Console.WriteLine("Failed");
94
Console.WriteLine("{0} Exception caught.", e);
98
System.Console.WriteLine("Expecting: " + testResult);
99
System.Console.WriteLine("Result: " + result);
101
if (compareStrings(result,testResult)) {
102
System.Console.WriteLine("Success");
104
System.Console.WriteLine("Failed");