This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm an absolute beginner with Java and XML. I know XML fairly well. I would really appreciate it if someone could point me to a tutorial or a book that explains how to read and generate XML files using Java.
Now, for more helpful APIs, the tutorial mentioned above is going to be the best source. I can help you focus by pointing out the parts you really want to see. This document tells you how to build a DOM (document object model) using API calls, and then this page tells you how to turn a DOM into an XML file on disk.
Finally, here's the documentation page for the JDOM project; JDOM is similar to the standard DOM API, but simpler (and non-standard.) You pays your nickle and you makes your choice.
I'm a newbie with both of the above and I could really use some good and fast teaching help, and of course, I would really really appreciate it.
Author and all-around good cowpoke
Joined: Mar 22, 2000
If this was my problem I probably would start by thinking about how to represent the data points both as Java objects and as XML Elements.
In some projects where a Java object represents some sort of unit of data, I have given the class a toXML( Writer out ) method and a constructor that takes the corresponding XML Element.
There are lots and lots of toolkits for transforming XML to objects and back if you don't want to tackle the problem that way. Browse some of the recent discussions here for examples or do a search for "java xml serialization".