Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate xml against schema

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to validate a xml file against a schema using SAX.

My problem is, that no error messages is thrown, even if I change the xml file to not match the schema. The method always return true.

What could be the problem?

I use xerces2 java 2.9.1.

 
kri shan
Ranch Hand
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to validate the same xml and xsd using xml tools first. - xmlSpy..
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to validate the xml file using the online validator at:
http://www.oioubl.info/validator/default.aspx

In the xml file I changed the element called "UBLVersionID" to "UBLVersionID2" to be able to throw the validation error. This change is also visible using the online validator.

The result of the validation:


Any ideas how I can find out what is wrong in my code?
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright it works now.

The problem was that I called the wrong error handler. My mistake!

It should be "new DOMErrorHandler()" and not "new org.xml.sax.helpers.DefaultHandler()".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic