Skip to main content

[Unmarshaller] - How can jaxb be useful without knowing the XSD elements?

2 replies [Last post]
paco84
Offline
Joined: 2008-02-02
Points: 0

Hi,

I'm new to jaxb. I saw a lot of examples where there was a cast for the object returned from the unmarshaller like this:

Collection collection= (Collection) objFactory.createCollection();
Collection.BooksType booksType = objFactory.createCollectionTypeBooksType();
BookType book = objFactory.createBookType();

This means that Collection is a XSD element and a XML tag and BookType the type of the object contained by Collection. Now I was wondering: how am i suppose to know previously which kind of elements are defined in the XSD that my program will receive? If i don't know this information, is jaxb totally useless?

I'm asking this because I've to develop a program that receives as input a db in xml format with related xsd. According to the xsd, the program will show the db structure to the user that will chose which fields he needs to store in his own db, and in which fields of his own db the data have to be stored.

Thanks to everybody for the help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ahashim
Offline
Joined: 2006-02-10
Points: 0

If you can generate an XML file from the database which contains all expected elements, using some tools, you can generate XSD from the XML file.

paco84
Offline
Joined: 2008-02-02
Points: 0

Are you sure that will be the correct xsd? I mean, can happen that a xml file doesn't contain all the possible tags, maybe because they are not compulsory (minOccur = 0) or some attribute. How can be possible to create the right xsd from a xml file? I think that the xsd generated will be almost the right one, almost. For sure right for that xml, but not for all the xml that can be generated from the "official" xsd. Am i wrong?