• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah!
You do help me a lot.Now the problem is resolved.
Thanks.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how do you automate this instead of hardcoding the data? I want to do the same thing but I need to input JTable data into the xml file line by line. Any thoughts on how to achieve it? Also, it would be helpful if you also helped me with writing filtered jtable data into the file. Thanks in adv.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic