> The XQuery Processor
# Copyright 2006-2008 The FLWOR Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require '/home/pfkeb/zorba/branches/0.9.5-rc1/build/swig/ruby/zorba_api' def example1(zorba) xquery = zorba.compileQuery("1+2") print xquery.execute() xquery.destroy() end def example2(zorba) xquery = zorba.compileQuery("(1,2,3,4,5)") iter = xquery.iterator() iter.open() item = Zorba_api::Item::createEmptyItem() while iter.next(item) do print item.getStringValue() print "\n" end iter.close() iter.destroy() xquery.destroy() end def example3(zorba) begin xquery = zorba.compileQuery("1 div 0") print xquery.execute() rescue RuntimeError => e print e ensure xquery.destroy() end end def example4(zorba) begin xquery = zorba.compileQuery("for $i in (1,2,") print xquery.execute() rescue RuntimeError => e print e ensure if not xquery.nil? then xquery.destroy() end end end def example5(zorba) dataManager = zorba.getXmlDataManager() dataManager.loadDocument("books.xml", "<books><book>Book 1</book><book>Book 2</book></books>") xquery = zorba.compileQuery("doc('books.xml')//book") print xquery.execute() xquery.destroy() end def example6(zorba) dataManager = zorba.getXmlDataManager() dataManager.loadDocument("books.xml", "<books><book>Book 1</book><book>Book 2</book></books>") xquery1 = zorba.compileQuery("insert node <book>Book 3</book> into doc('books.xml')/books") if xquery1.isUpdateQuery() then xquery1.applyUpdates() end xquery2 = zorba.compileQuery("doc('books.xml')//book") print xquery2.execute() xquery1.destroy() xquery2.destroy() end store = Zorba_api::InMemoryStore.getInstance() zorba = Zorba_api::Zorba.getInstance(store) print "Example1:\n" example1(zorba) print "\n\n" print "Example2:\n" example2(zorba) print "\n" print "Example3:\n" example3(zorba) print "\n\n" print "Example4:\n" example4(zorba) print "\n\n" print "Example5:\n" example5(zorba) print "\n\n" print "Example6:\n" example6(zorba) print "\n\n" zorba.shutdown() Zorba_api::InMemoryStore.shutdown(store)