import javax.xml.transform.* import org.xmldb.api.* // eXistに接続 db = Class.forName("org.exist.xmldb.DatabaseImpl").newInstance() DatabaseManager.registerDatabase(db) col = DatabaseManager.getCollection( "xmldb:exist://localhost:8080/exist/xmlrpc/db", "admin", "admin"); // XQueryを実行 query = ''' for $c in //country[population_growth < 0] order by $c/name return <country> {$c/name, $c/population_growth} </country> ''' service = col.getService("XQueryService", "1.0") service.setProperty(OutputKeys.INDENT, "yes") service.setProperty(OutputKeys.ENCODING, "UTF-8") compiled = service.compile(query) result = service.execute(compiled) // 結果を取得 results = result.getIterator() while(results.hasMoreResources()){ res = results.nextResource() if( res.getResourceType().equals("XMLResource") ){ println(res.getContent()) } } col.close()
※以下のjarをeXistからgroovyのlibディレクトリにコピーします。
exist.jar
lib/core/xmldb.jar
lib/core/xmlrpc-client-3.1.2.jar
lib/core/xmlrpc-common-3.1.2.jar
lib/core/ws-commons-util-1.0.2.jar
動作環境
groovy 1.8.2, JDK6 Update 27, eXist 1.4.1
0 件のコメント:
コメントを投稿