import org.xmldb.api.base.*; import org.xmldb.api.modules.*; import org.xmldb.api.*; import org.exist.xmldb.XQueryService; import java.io.*; public class QueryExample { public static void main(String args[]) throws Exception { String driver = "org.exist.xmldb.DatabaseImpl"; Class cl = Class.forName(driver); Database database = (Database)cl.newInstance(); DatabaseManager.registerDatabase(database); Collection col = DatabaseManager.getCollection( "xmldb:exist://localhost:8080/exist/xmlrpc/db" ); XQueryService service = (XQueryService) col.getService("XQueryService", "1.0"); service.setProperty("indent", "yes"); try{ BufferedReader in = new BufferedReader(new FileReader("d://test.xquery")); //put your xquery file path here //make sure the query path in your xquery is correct String inContent = ""; String temp = in.readLine(); while (temp != null){ inContent = inContent + temp + "\n"; temp = in.readLine(); } in.close(); //System.out.println(inContent); ResourceSet result = service.query(inContent); ResourceIterator i = result.getIterator(); while(i.hasMoreResources()) { Resource r = i.nextResource(); System.out.println((String)r.getContent()); } }catch(IOException e){ System.out.println("read file error."); } } }