This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Document object into Database" Watch "Document object into Database" New topic
Author

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
Brian
David Peterson
author
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...

David
Joe Nguyen
Ranch Hand

Joined: Apr 20, 2001
Posts: 161
Brian
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Document object into Database
 
Similar Threads
XML convertion to java.sql.Clob
Conversion into SQL Result Clob from a String
Converting a String to Clob for insert into DB
use of CLOB,help me.
How to store whole XML in a table of a database