1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import javax.xml.transform.OutputKeys;
import org.exist.storage.serializers.EXistOutputKeys;
import org.exist.xmldb.EXistResource;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.XMLResource;
/**
* Retrieve a document from the database. To run this example enter:
*
* java -jar start.jar org.exist.examples.xmldb.Retrieve collection document
*
* in the root directory of the distribution.
*
* @author Wolfgang Meier <meier@ifs.tu-darmstadt.de>
*/
public class Retrive {
protected static String driver = "org.exist.xmldb.DatabaseImpl";
protected static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
public static void main(String args[]) throws Exception {
String collection = "db";
// initialize database drivers
Class<?> cl = Class.forName(driver);
Database database = (Database) cl.newInstance();
DatabaseManager.registerDatabase(database);
System.out.println(URI + collection);
// get the collection
Collection col = DatabaseManager.getCollection(URI + collection);
col.setProperty(OutputKeys.INDENT, "yes");
col.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, "no");
col.setProperty(EXistOutputKeys.PROCESS_XSL_PI, "yes");
XMLResource res = (XMLResource)col.getResource("examples.xml");
if(res == null)
System.out.println("document not found!");
else {
System.out.println(res.getContent());
System.out.println("Size: " + ((EXistResource)res).getContentLength());
}
}
} |
Partager