How to Know Schema Before Unmarshalling?

There are a few different options: Option #1 - Create the JAXBContext on Multiple Domain Models If the models for the two schemas are compatible (are completely independent, or share types that are annotated the same way), then just create the JAXBContext on all of the domain objects instead of having one per schema. bdoughan.blogspot.com/2010/08/using-xmla... Option #2 - StAX Input If having different XML schemas means having different root elements I would create a StAX XMLStreamReader look at the root element and then choose which marshaller to use. Then unmarshal that XMLStreamReader.

Option #3 - Validate the XML Document First You could use the javax.xml. Validation APIs to validate the document first and then based on the results choose the unmarshaller.

1 You know, actually, I was waiting for you because I know you got a good command on XML parsers and JAXB. Will let you know about it. Right now thinking about whether to use JAXB generated class as a root node of JTree, or use DefaultMutableTreeNode and maintain actual POJO simultaneously with that as a userObject.

– Adeel Ansari Apr 14 at 10:25 Doing it with the second option. Once again thanks for your inputs. – Adeel Ansari Apr 18 at 3:34.

Perhaps you should look at using a SAX parser and process the two structures manually in one handler. Another possibility is to create a new schema that allows the two options. If I had complete control of the schemas I would look at the second option.

If the response schemas were simple and/or shared a similar structure I would look at using SAX.

Thanks for your suggestions. I would try the second option. If that doesn't work, even then I believe I would be able to use the SAX parser, if not completely but at least to check the first element.

+1 – Adeel Ansari Apr 14 at 6:28.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions