• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML data in DefaultTableModel

 
kalle svensson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! i need to display the data from an xml file in a DefaultTableModel using the addRow method. in my table there are three
columns named "symbol", "info" and "value", so i must create arrays of string objects from nodelists and insert them in the model with something like -
addRow(new Object[] { getSymbolData, getInfoData, getValueData } ); but im stuck and cant seem to get it right. if anyone can give me an example on
how this is done then it would be very much appreciated! im just a learner.
 
Campbell Ritchie
Marshal
Posts: 52558
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a "beginning" question. Moving.
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be more convenient for us to start with your not-quite-working code, instead of to write a whole tutorial specifically tailored for this question.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kalle svensson wrote:i need to display the data from an xml file in a DefaultTableModel using the addRow method. in my table there are three
columns named "symbol", "info" and "value", so i must create arrays of string objects from nodelists and insert them in the model with something like -
addRow(new Object[] { getSymbolData, getInfoData, getValueData } ); but im stuck and cant seem to get it right.

Are you having trouble with the addRow part, or the getSymbolData part? In other words, is this a JTable qustion or an XML question?

If it's a JTable question, I would usually recommend extending AbstractTableModel and maintaining your own row data, rather than using DefaultTableModel. But I don't know enough details to necessarily make that recommendation here.
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


but im stuck and cant seem to get it right


Well, based on a single line of code its hard to tell whats wrong, but the single line of code looks fine.

Start by walking not running. So first create a table using static data. Something like:



Then you know whether the problem is with that line of code or the parsing of the XML. Once you solve the first problem you move on to the second.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
 
kalle svensson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, again! thanks for all the previous tips and hints on how i should solve the problem i posted but i have finally got it to work
as i wanted it to. this is still only a basic code sample. forgive my bad english writing. please feel free to comment this code
or leave some feedback of any other kind.

the first codewrap is a simple xml-document and is saved in a file called rowdata.xml

and here is the java code. i havent commented the entire structure but i guess its obvious what i im saying anyway
it displays the data in the previous xml document in a DefaultTableModel using the addRow(Object[] obj) method thats what
i wanted it to do but i missed an error ive made in the xml syntax ...


 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!