0 Replies Latest reply on Jun 17, 2011 11:41 AM by 869591

    Schema Validation on attributes of an element in XML againt XSD schema


      I had generated artifact java classes from XSD schema file.Now i am validatiing one sample XML document by using these classes in JAXB.The XML document is validated successfully.but only elements are validated ,but not attributes of that elements.for example ,i am giving wrong element which is not defined inside the schema file,it throws validation error as expected ,whereas validation against wrong attributes of elements in XML it is not working anyway,it does not throw any validation errors,but it should throw validation errors.kindly help me to solve this issue.

      Here The sample validation code snippets :

      import javax.xml.bind.ValidationEvent;
      import javax.xml.bind.ValidationEventHandler;
      import javax.xml.bind.ValidationEventLocator;

      public class MyEventHandler implements ValidationEventHandler{

           public boolean handleEvent(ValidationEvent ve) {
                if (ve.getSeverity()==ValidationEvent.FATAL_ERROR ||
                          ve .getSeverity()==ValidationEvent.ERROR){
                     ValidationEventLocator locator = ve.getLocator();
                     //Print message from valdation event
                     System.out.println("Invalid booking document: "
                               + locator.getURL());
                     System.out.println("Error: " + ve.getMessage());
                     //Output line and column number
                     System.out.println("Error at column " +
                               locator.getColumnNumber() +
                               ", line "
                               + locator.getLineNumber());
                return true;


      Unmarshaller unmarshaller = jc.createUnmarshaller();
      unmarshaller.setEventHandler(new MyEventHandler());