Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Document object into Database  RSS feed

 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can convert the Document to an XML string using a javax.xml.transform.Transformer. Something like this...

David
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!