aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to read and write the data in XML file 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 "How to read and write the data in XML file" Watch "How to read and write the data in XML file" New topic
Author

How to read and write the data in XML file

sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear ALL,

Below given the code i am retrive from Database.

Could you please tell me how this data should be read and write in XML file.



Please suggest.

Thanks in advance.
Regards,
Sumanta
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14111
    
  16

There are several APIs in Java for working with XML.

Unfortunately, the standard Java APIs for working with XML, in the package javax.xml and subpackages, are not the easiest and best to use in many cases. The standard APIs seem to be more focused on parsing XML and are not very good at outputting XML.

There are many alternatives, such as XOM (which XML guru Michael Kay said good things about on the Devoxx conference where I was recently), JDOM, XStream and many others.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
If you are using the Oracle Database you can use the following pacakage.

select dbms_xmlgen.getxml('select sysdate from dual',0)xml from dual;

In the place of the 'select sysdate from dual' you can specify your query.

The data will automatically be generated in XML. You can also use the DOM Parser in java if this doesn't suit your requirement.


They say you have to be the first, the best or different. I say, is it too much to ask for all three.
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear All,

Below given is the code.I am retrive the data from database and trying to export in the XML file.
I didnot get any compilation error.But i dont know why in my code the data is not export in the xml file.
hERE I TRIED WITH FNAME for column.

Please suggest me how i will fix this issue.



Thanks in advance.

Regards,
Sumanta Panda
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You don't ever close the output stream. You should do that.

Also, do you only have one record to output? If not, then you are reusing the same file for all records and you are going to end up with one file containing only the last record.
sumanta panda
Ranch Hand

Joined: Jun 23, 2008
Posts: 224
Dear Paul Clapham,

As per your advise i have closed the conncetion.Still i am getting the same issue(Data is not export in the file.

Please suggest me for the needful.



Thanks for your time.

Regards,
Sumanta
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41532
    
  53
fos = new FileOutputStream(fileName);

Do you really want to create a new file for each DB record? Do you have code somewhere to assign them different filenames?


Ping & DNS - my free Android networking tools app
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Here's another guess: your ResultSet doesn't contain any records. But this is a simple thing which you could find out for yourself by a little bit of debugging. Have you done any of that? Do you know which lines of code are being executed?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
If you retrieve data from database using Hibernate ORM Framework, then all you need to do to get XML-based version is call toXML() on a single object.

Very easy! Hibernate is Great!
 
Don't get me started about those stupid light bulbs.
 
subject: How to read and write the data in XML file