I think this might be possible, but it is definitely not the best way to produce Java code from XML. You should take a look at XML-Binding technologies like JAXB or Castor. With that you can produce Java code that is equivalent to a given XML schema or DTD document.
So if you have an XML schema (or DTD) that defines the structure of you XML, you can easily produce Java code by applying the API given by one of the technologies mentioned above.
I recommend JAXB, since Castor does not comply to the latest XML schema specification (as far as I know).