以文本方式查看主题

-  课外天地 李树青  (http://njcie.com/bbs/index.asp)
--  信息检索原理课件  (http://njcie.com/bbs/list.asp?boardid=16)
----  利用HTTP请求方式获取eXist查询结果的简单程序  (http://njcie.com/bbs/dispbbs.asp?boardid=16&id=747)

--  作者:admin
--  发布时间:2009/5/27 22:46:25
--  利用HTTP请求方式获取eXist查询结果的简单程序

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class Exec {
    public static void main(String args[]) {
        FileOutputStream fos;
        URL url;
        URLConnection urlConnection;
        InputStream is;
        int i;

        try {
            fos = new FileOutputStream("results.xml");
            url = new URL(
                    "http://localhost:8080/exist/servlet/db/?_query=for $p in //stu where contains($p,\'exam\') return $p");
            urlConnection = url.openConnection();
            is = urlConnection.getInputStream();

            i = is.read();
            while (i > 0) {
                fos.write(i);
                i = is.read();
            }
            fos.close();
            is.close();
        } catch (IOException e) {
        }
    }
}

[此贴子已经被作者于2010-12-14 09:41:55编辑过]