aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML Schema Validation with Xerces 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 "XML Schema Validation with Xerces" Watch "XML Schema Validation with Xerces" New topic
Author

XML Schema Validation with Xerces

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
This concerns a problem with parsing an XML instance with it's schema using Xerces as the parser and a SAXParser object.

There is a annoying "no grammar found" error message when attempting to parse the file.

The schema is in the same directory as the instance file.

We are setting the validation feature to true and setting the file-name of the schema in the schemaLocation attribute after the namespace (see below).



Is there a bug with the schemaLocation attribute?

Is there a better way to specify the schema location?

Note, the file is being parsed for well-formedness. But, it is not being validated with the schema.

Any help is greatly appreciated.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

James Clark wrote:The schema is in the same directory as the instance file.

And are you parsing the XML document in such a way that the parser can tell what directory it's in? (If you give the parser a FileInputStream, for example, it can't generate a base URI from that and therefore can't find the parser relative to the base URI.)
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thanks.

And are you parsing the XML document in such a way that the parser can tell what directory it's in?


That is what I am asking about. I am not using a FileInputStream object. Below is the method.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Well... not that I think it's going to help... but you could try
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thanks Paul.

There isn't much time to waste fighting with Xerces. We have switched to the javax.xml.validation API which uses three objects to validate documents: SchemaFactory, Schema, and Validator.




I imagine that it is using the Xerces implementation that comes bundled in the Java SDK. There probably is some method that will allow us to switch to the Apache version.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Schema Validation with Xerces
 
Similar Threads
validate schema in DOM
building error when validating against schema using jdom
XML validation issue in Xerces
xerces : Parsingproblem when "include" one or more Schema in another
SAX parse and validate with XSD