Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create GUI from and saving stuff to XML

 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused about the approach I should take on this.

I am using XML as my data-model. A web-based GUI would prepare the GUI from this XML. Let's say this is a Book XML where using the GUI user could (1) select his preferred chapter and (2) Save this choice. To generate the GUI and saving user's preference I plan to use the same XML (say master.xml).

The XML:


The GUI can certainly be made from this, a drop down containing all the chapter titles and a button to save the preference. When the user saves it, the XML would be saved (as say user_xyz.xml) and looks like:


So far so good Imagine now that the author adds few more chapters so the XML now becomes:


I see no problem in saving a new preference the GUI dropdown will now display four chapters instead of two. However, what if the user XYZ decides to alter his preference, if my GUI is created using "user_xyz.xml" the GUI is not aware of the additional two chapters now available. If it is created using "master.xml" it has no knowledge of the user's previous preference.

I hope I made myself clear. Should then my approach to creating the GUI be parsing both master and user's XML and then create it, could be taxing if XML is complex and bulky. Or should I update the user's xml every time master changes, again how will I update it. Or is there any other suitable approach?

Thanks for your time.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem stems from the fact that you're mixing two different things with a different lifecycle -- the chapters and the user's preferences. Try separating the two into their own files and then "merging" them where appropriate.

For example:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic