This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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: 1368
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
 
Similar Threads
SAX XSD Validation. Error callback is called twice.
schema validator
schema validator
all validation error using saxParser
Validating XML aginst XSD