- 保存文件
- 取回文件
- 查询
1、QueryFileSOAP.java
package com.neohope.existdb.test;
import org.exist.soap.Query;
import org.exist.soap.QueryResponse;
import org.exist.soap.QueryService;
import org.exist.soap.QueryServiceLocator;
import java.net.URL;
import java.nio.charset.Charset;
public class QueryFileSOAP {
public static void QueryXML(String xquery, String user, String pwd) throws Exception {
QueryService service = new QueryServiceLocator();
Query query = service.getQuery(new URL("http://localhost:8080/exist/services/Query"));
String sessionId = query.connect("neotest", "neotest");
byte[] queryData = xquery.getBytes(Charset.forName("UTF-8"));
QueryResponse resp = query.xquery( sessionId, queryData );
System.out.println( "found: " + resp.getHits() );
if(resp.getHits() == 0) {
return;
}
else {
//get 10 results
byte[][] hits = query.retrieveData(sessionId, 1, 10,
true, false, "elements").getElements();
for (int i = 0; i < hits.length; i++) {
System.out.println(new String(hits[i], "UTF-8"));
}
}
query.disconnect(sessionId);
}
public static void main(String args[]) throws Exception {
String user = "neotest";
String pwd = "neotest";
String query ="for $name in collection('/db/CDA')/ClinicalDocument/recordTarget/patientRole/patient/name \n" +
"return \n" +
"<name>{$name}</name> ";
QueryXML(query, user, pwd);
}
}