Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Schema Validation with Xerces

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21319
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... not that I think it's going to help... but you could try
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic