Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we convert an xml file to create java file

 
Ritu Kapoor
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've an xml file containing all relevant info relate to class - like class name, methods, attributes. My question is how can I convert that into java file.

Thanks,
Ritu
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use xStream. you can find more information on their homepage
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ritu,

I would use xlst transformations for this. In fact I already did this to create java classes based on a set of XML files containing a data model, but unfortunately I don't have the code right here, now.

With xslt you can create text files from your XML and it is no problem to create text files that are .java files.
Maybe you can try to google "xslt generate java" to get some examples how to do it.

One hint:

I ran into the problem to need an XSLT processor with enhanced functionality, because I had to write more than one java-file for one XML-file. I think I used XALAN for this, but there should be more XSLT processors with this feature.



John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic