aspose file tools*
The moose likes XML and Related Technologies and the fly likes Build and Populate java classes at Runtime from XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Build and Populate java classes at Runtime from XML file" Watch "Build and Populate java classes at Runtime from XML file" New topic
Author

Build and Populate java classes at Runtime from XML file

saakshi joshi
Greenhorn

Joined: Aug 20, 2009
Posts: 3
Hi,
I am looking out for a tool or library for following requirement.
1] I have XML file e.g. something like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Person>
<firstname>Joe</firstname><lastname>Walnes</lastname>
<phone><code>123</code><number>1234-456</number></phone>
<fax><code>123</code><number>9999-999</number></fax>
</Person>
I don't have XSD file of this XML .

2] I don't have 'Person' java class .
Is there any tool or library available which will parse XML file and at runtime build Java class 'Person' with getter and setter for Tags like getFirstName() and setFirstName() and so on .
Similarly , it will populate the value of 'Person' class with values in xml e.g setting 'firstname' in 'Person' class as 'Joe' and so on ?


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42283
    
  64
How would your code use those classes if they didn't exist at compile time? They couldn't implement some common interface, as each XML file would have different tags, correct?

Maybe take a step back, and tell us what you're trying to achieve. For example, would this code really be expected to handle unknown XML formats? If so, what does it do?

If you did have a Person class, then you could use one of several available libraries, such as Apache Commons Digester, to populate them, or a more general API such as JAXB that can do two-way mapping.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Build and Populate java classes at Runtime from XML file