I am a brand new to coderanch, so I am sorry if i break any styling-rules. I am working with JDOM in order to create my primary save data. I want to have 1 document for everything. In order to do that, I have created a model for an XML page. Initially at "program installation" I want to have a blank XML document with only the <program> tag. Later, I want to be able to create new users. <user name="user1" password="theirPassword"> I want to be able to add a new user later on so that the date would look like:
So, reading between the lines, it looks like you have some code which uses JDOM to parse an XML document into a JDOM Document object. And you're asking how to write code to change that Document by adding new elements. Well, to find that out I would recommend reading a JDOM tutorial. I used the google keywords "jdom tutorial" and the first link I got back was this one: Easy Java/XML integration with JDOM. It looks like Part 2 directly addresses your specifc question, so good luck! And welcome to the Ranch!
Thanks, that was a good resource, but still did not really help me solve my current problem. Here is my code as it now is. (the formatting is a little off because I copied and pasted only parts of the code.)
do you have any idea what I am doing wrong, and why the initial information is being erased? Am I just being stupid and need to use 'user' as a namespace and 'userChosenName' as the element tag? I have already spent hours on google searching without results to this particular issue.
>Am I just being stupid and need to use 'user' as a namespace and 'userChosenName' as the element tag? That is not the problem. Sometimes we rely on some kind of imagination on the cause of a problem only to find it harder to unlearn the experience of wrong diagnosis. Namespace and tag name have nothing to do with the problem.
>do you have any idea what I am doing wrong, and why the initial information is being erased? This is the problem and how to rectify it. Since you want to first read the data from a file and then update the same file, your writer and reader are actually instantiated with the same file path. Here pose a problem. If you instantiate writer immediately before or after the reader being instantiated, the file would thereby be empty. Hence reader's functioning will be adversely interferred. This is how you rectify the code preserving the general structure of it.
 Comment out the line #12. Just not to instantiate the writer, yet.
 Add these between lines #26 and #27.
Then you should find the file being updated preserving the existing data plus the new.