package org.basex.examples.xmldb;
import org.basex.api.xmldb.BXCollection;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.XMLResource;
import org.xmldb.api.*;
/**
* This class serves as an example for creating a database with the XML:DB API.
*
* @author BaseX Team 2005-11, BSD License
*/
public final class Test {
/** Database driver. */
public static final String DRIVER = "org.basex.api.xmldb.BXDatabase";
/**
* Main method of the example class.
* @param args (ignored) command-line arguments
* @throws Exception exception
*/
public static void main(final String[] args) throws Exception {
System.out.println("=== XMLDBCreate ===");
try {
// Register the database
Class<?> c = Class.forName(DRIVER);
Database db = (Database) c.newInstance();
DatabaseManager.registerDatabase(db);
System.out.println("\n* Create a new collection.");
// Create a new collection
BXCollection col = new BXCollection("Collection", false);
// ID for the first document
String id1 = "doc1";
// Content of the first document
String doc1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"</tag>";
// ID for the second document
String id2 = "doc2";
// Content of the second document
String doc2 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"</tns:tag>";
System.out.println("\n* Create new resources.");
// Create a new XML resource with the specified ID
XMLResource res1 = col.createResource(id1, XMLResource.RESOURCE_TYPE);
XMLResource res2 = col.createResource(id2, XMLResource.RESOURCE_TYPE);
// Set the content of the XML resource as the document
res1.setContent(doc1);
res2.setContent(doc2);
System.out.println("\n* Store new resource.");
// Store the resource into the database
col.storeResource(res1);
col.storeResource(res2);
col.close();
} catch(final XMLDBException ex) {
// Handle exceptions
System.err.println("XML:DB Exception occured " + ex.errorCode);
}
}
}
-- Andreas
Am 25.03.2011 um 08:34 schrieb Andreas Weiler:
Hi Frans,
could you send me your java class, so i can have a look at it.
-- Andreas
Am 25.03.2011 um 00:01 schrieb frans@planet:
I'am accessing BaseX 6.5.1 through the XMLDB API. There are some issues with namespace handling when storing resources. Let me clarify that with some examples.
First example
I want to store the following as a resource:
String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"</tag>";
Second example
I want to store the following as a resource and INTPARSE = false:
String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"</tns:tag>";
This yields the following exception:
org.xmldb.api.base.XMLDBException: "null" (Line 1): The prefix "tns" for element "tns:tag" is not bound
Third example
I want to store the following as a resource and INTPARSE = true:
String example = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
"</tns:tag>";
This yields <tns:tag xmlnstns="
http://example.org"/> in the GUI. The colon is missing in ' xmlnstns' . So this is not OK.
Are the second and third examples bugs or should I change some setting to get a proper handling of namespaces?
Regards,
Frans
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk