You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "MOLNAR,ANGELA (HP-SanDiego,ex1)" <an...@hp.com> on 2002/12/20 01:00:14 UTC

Need help with schema validation using a SAX parser

Hello,

I'm a new user of Xerces, and I've encountered a phenomenon that is
confusing me.  Here is the section of code I'm using to validate an xml file
with a schema using a SAX parser:

	Validator v = new Validator();
	try {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser parser = spf.newSAXParser();
      		XMLReader reader = parser.getXMLReader();
      		reader.setFeature("http://xml.org/sax/features/namespaces",
true);
      		reader.setFeature("http://xml.org/sax/features/validation",
true);
 
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
 
reader.setProperty("http://apache.org/xml/properties/schema/external-noNames
paceSchemaLocation",sSchemaLocation);
		parser.parse(new File(sFileName), v);
	} catch (Exception e) {
		System.out.println(e);
	}

When I use an old version of xercesImpl.jar and xmlParserAPIs.jar that I got
from an XML class (downloaded January 29th, 2002) this code works fine.
However, when I replace these jar files with new ones that I just downloaded
from the Xerces site (last modified December 18th, 2002), I get this error
message:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema
document 'XMLData.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.

I have verified my schema file, and it's in the same directory as the xml
file so it can find it.  This code works as is with the old version of the
jar files.  What am I doing wrong?

Thank you very much.

Angela Molnar


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org