Im having serious trouble adding a dom tree to the database
my statement .setContentAsDom won't accept my dom tree!
I have one class making a dom tree..:
import org.w3c.dom.*;
import org.apache.xerces.dom.DocumentImpl;
public myclass....
public Void makeDoc...
Document doc= new DocumentImpl();
// Create Root Element
Element root = doc.createElement("profile");
...
..
//sending doc to saving class
myAddDocument.add(doc);
//end class
..and another class where I try to save this document to a database i have set
up
imports...
public class AddDocument {
public void add (Document doc) throws Exception{
Collection col = null;
try {
String driver = "org.dbxml.client.xmldb.DatabaseImpl";
Class c = Class.forName(driver);
Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);
col =
DatabaseManager.getCollection("xmldb:dbxml:///db/addressbook");
XMLResource document = (XMLResource) col.createResource(null,
"XMLResource");
document.setContentAsDom(doc); file://doc is of type
org.apache.xerces.dom.Document
col.storeResource(document);
System.out.println("Document inserted as " + document.getId());
}
catch (XMLDBException e) {
System.err.println("XML:DB Exception occured " + e.errorCode + " " +
e.getMessage());
}
finally {
if (col != null) {
col.close();
}
}
}
}
I get a compilation error on this line
document.setContentAsDom(doc);
The error is
.\AddDocument.java:55: Cannot resolve symbol
symbol : Method setContentAsDom (org.Apache.xerces.dom.DocumentImpl)
location: interface org.xmldb.api.modules.XMLResource
document.setContentAsDom(doc);
In the API i see that the method takes a org.w3c.dom.Node as argument
(setContentAsDOM(org.w3c.dom.Node content))
How can i create a dom document so that it is accepted by the setContentAsDom
method??
If someone has any experience doing this, I would gratefully accept some help
:-)
�yvind