1 package test.xmldb.other; 8 9 import org.w3c.dom.Document ; 10 import org.xmldb.api.DatabaseManager; 11 import org.xmldb.api.base.Collection; 12 import org.xmldb.api.base.Database; 13 import org.xmldb.api.modules.XMLResource; 14 import org.apache.log4j.Logger; 15 import test.xmldb.Constants; 16 19 public class RetrieveDocument implements Constants{ 20 21 Logger logger = Logger.getLogger(RetrieveDocument.class); 22 23 24 public RetrieveDocument() { 25 try { 26 Class c = Class.forName(driver); 27 28 Database database = (Database) c.newInstance(); 29 System.out.println("Registring Database " + database); 30 DatabaseManager.registerDatabase(database); 31 Collection col = database.getCollection(collectionURI); 32 System.out.println("Got Collection " + col); 33 XMLResource resource = (XMLResource) col.getResource(resourceName); 34 System.out.println("Got resource " + resource + " for " + resourceName); 35 36 Document doc = (Document )resource.getContentAsDOM(); 37 System.out.println("Retrieved the Document with root: " + doc.getDocumentElement().getTagName()); 38 String content = (String )resource.getContent(); 39 System.out.println("here's the content:\n" + content); 40 col.close(); 41 } 42 catch (Exception e) { 43 e.printStackTrace(); 44 } 45 } 46 47 public static void main( String args[] ) { 48 new RetrieveDocument(); 49 } 50 } 51 | Popular Tags |