• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Document object into Database

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can convert the Document to an XML string using a javax.xml.transform.Transformer. Something like this...

David
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic