• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML-JAXB ValidationException  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a sample aplication, to unmarshal the data from the xml file. Please go through the below code and help me out.

Code:
public Test{
public Test() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new File("Customer.xml"));

JAXBContext jc = JAXBContext.newInstance("generated", this.getClass().getClassLoader());

Unmarshaller unm = jc.createUnmarshaller();

Validator validator = jc.createValidator();
validator.validate(doc);

Customer cust = (Customer) unm.unmarshal(new FileInputStream("Customer.xml"));

}
catch(ValidationException ve){
ve.printStackTrace();
}
catch (Exception error) {
error.printStackTrace();
}
}

public static void main(String[] args) {
new Test();
}
}


Exception:

javax.xml.bind.ValidationException: the object parameter to validate() or validateRoot() is not validatable
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!