It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes How to save the content withen a table into a XML file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to save the content withen a table into a XML file?" Watch "How to save the content withen a table into a XML file?" New topic
Author

How to save the content withen a table into a XML file?

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
I have a table like this:
-----------------------------
Name Sex
Superman M
Allen M
... ...
------------------------------
columName[] = {"Name", "Sex"};
data[] = {"Superman", "M", "Allen", "M", ...};
tableModel = New MyTableModel(columnName, data);

Now I want to press a "Save" button to save this to a XML file. How do I construct the file? I'm not familer with XML.
Thanks a lot.
your sincerely letter.


To be or not to be. It's a question.
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
hi,

i am sending sample code about how to write data to xml file. java to xml communication is possible with jdom.jar. first down load it and use this code to write data to xml file.

Needed changed...
1) This program will create "test.xml" in your "C Direcotry"
2) that file will contain one root element "Books" and several "Book"
sub tags.

<Books> <!-- this is root tag of xml file>
<Book>
<Title>AAAAAA1</Title>
<Author>asdf</Author>
<Cost>78</Cost>
</Book>
<Book>..........</Book>
<Book>..........</Book>
<Book>..........</Book>
</Books>
3)This code will write data to xml file to append data to xml file remove the commentsa and run the code.



Hope this helps u
All The Best
Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
Yeah!
You do help me a lot.Now the problem is resolved.
Thanks.
 
GeeCON Prague 2014
 
subject: How to save the content withen a table into a XML file?