I am learning XMLBeans which is an open source tool to convert from XML to java beans.
I want to know if using XMLBeans we can convert from Java beans to XML. Is that possible?
Yes it is. First step is to create a schema file and then compile it with the scomp tool. This will generate a jar file containing the java classes that map to the elements in your schema.
The next bit is bit trickier. The generated files do not include the source. So you're going to have to use javap to generate the byte code. Using this and a bit of trial and error, you can work out how to use the various classes. This bit is time consuming and a little annoying, so if anybody out there has a better way of doing this, please post a note. Once you've figured out how to use the classes, populate them with data in your application. When you're ready, call the .toString() method on the root node and this will generate your xml. BINGO !!!
Also , say we have an xml file, is it possible to parse that xml using XMLBeans API?
Not quite sure with this one. I have'nt looked at this. If you do find out please post a note.