aspose file tools*
The moose likes XML and Related Technologies and the fly likes Validate xml against schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Validate xml against schema" Watch "Validate xml against schema" New topic
Author

Validate xml against schema

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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

Joined: Apr 08, 2004
Posts: 1382
Try to validate the same xml and xsd using xml tools first. - xmlSpy..
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
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

Joined: Jan 07, 2004
Posts: 270
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()".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate xml against schema