File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Document object into Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Document object into Database" Watch "Document object into Database" New topic

Document object into Database

Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
I know how to insert an XML file into a database Clob column, but I have an XML Document object. How do I convert the Document object into a String, or character array or something else useful so that I can insert it into a Clob?
We are using Oracle 8i along with the Apache Xerces parser and JAXP.
Thanks for the help
David Peterson
Ranch Hand

Joined: Oct 14, 2001
Posts: 154
You can convert the Document to an XML string using a javax.xml.transform.Transformer. Something like this...

Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
To convert a doc to string, loop through the doc and convert individual node to string.
//Convert an XML string to a real string
public static String xmlToString(Node _node) {
Node value = _node.getFirstChild();
if(value == null) {
return "";
return value.getNodeValue();
For your second question, I recommend to create an java object and convert the xml to java object. You can then access java object fields when persisting your data to the table
I agree. Here's the link:
subject: Document object into Database
jQuery in Action, 3rd edition