File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Generating Class Files from an XML Doc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Generating Class Files from an XML Doc" Watch "Generating Class Files from an XML Doc" New topic
Author

Generating Class Files from an XML Doc

Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
At the moment, I have written a small class to read in an XML File using a DOM Parser & create a class structure for the info in the XML File. The problem I am having, is that as it stands I need to know the format of the File & the classes are done at compile time. What I need to do next is to write a class that will read ANY XML File & create a corresponding class structure.
I would like to know if this is possible & if so, does anyone have any ideas/hints.....
Thanks,
Dave
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Dave,
All the XML files are text-based. You can safely assume it contains only ASCII characters.
Does that help?


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
Ajith,
Thanks for your reply...however by format I mean the names of tags etc....
For example, say I have a basic XML File -
<person>
<name> Dave </name>
<age> 22 </age>
<address>
<street> Main St </street>
<city> Dublin </street>
<country> Eire </country>
</address>
</person>
Currently, in my code I have an Object called Person, & an object called address. Person contains 3 variables - name, age, & an address object. address object contains 3 variables street, city, country.
To populate these classes, I need to know the names of the tags, & what tags the person tag contains.
What I want is to be able to do this without knowing these things, so that I can read in any XML File & create a class structure from it.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Hmmm.. in that case you will need to have access to the DTD or the Schema that describes the XML structure.
Since each type can have sub-types, content or a mixture of both, its going to be pretty tricky figuring out exactly what you need to describe the attributes - simple type versus objct references versus collections such as arrays etc. Remember you will also need to handle groupings and cardinalities.
Have you explored XML data-binding frameworks? Checkout the databinding spec from SUN. Eventhough it is still at the community process stage, it promises to alleviate a lot of "mapping" problems such as the one you're facing now.
Good luck( do share your success with us
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
Dave Donohoe
Ranch Hand

Joined: May 16, 2000
Posts: 73
Thanks again Ajith, I think this site is what I am looking for !
Your help is much appriciated !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generating Class Files from an XML Doc
 
Similar Threads
xml conversion
Storing parsed XML data into database
XML to database
Developing GUI through XML
Dynamic Array Resizing