By manishkg on Apr 25, 2007
If you are using JAXB for XML to Java binding and geting javax.xml.bind.UnmarshalException: Unexpected element blah blah blah... the first thing you can do is to call setValidating(true) on Unmarshaller object. i.e.
JAXBContext jc = JAXBContext.newInstance("com.sun.java.xml.ns.portlet.portlet_app_2_0");
// create an Unmarshaller
Unmarshaller u = jc.createUnmarshaller();
This will help in getting little more details about the problem. For example, if your schema has declared <sequence> constraints on certain elements and your XML is not following it, the validation handler will report that certain tag name (element) is NOT allowed at this place and what all possible elements can appear after certain element.
One caveat here - setValidating() is a deprecated method and should be used only for debugging purpose.