Shital, Add this to what you already had. It should be able to find the schema at that point. Do not use setValidation it is not in most recent versions.
// load schema\dtd parser.setFeature(LOAD_EXTERNAL_DTD, true); Doug -----Original Message----- From: Shital Joshi [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2003 5:51 PM To: [EMAIL PROTECTED] Subject: RE: validating an xml file using sax parser Hi Dmitri, What version of Xerces you are using? Because my parser complains about not finding "setValidation(true)" method. Thanks anyway, -Shital Joshi MFG Systems -----Original Message----- From: Dmitri Toubelis [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 29, 2003 5:37 PM To: [EMAIL PROTECTED] Subject: Re: validating an xml file using sax parser Shital, Try using parser.setValidation(true); instead of: parser.setFeature("http://xml.org/sax/features/validation", true); I don't know how to explain this, but it worked for me. -Dmitri ----- Original Message ----- From: "Shital Joshi" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, April 29, 2003 5:17 PM Subject: validating an xml file using sax parser > Hi Friends, > > I am trying to validate an xml file using sax parser. But my program never > finds schema file. Whether the schema file is there or not, it always throws > bunch exceptions like "Element type for "xml element" must be declared"... > I am sure I am doing something wrong in implementing the entity resolver > because the program never prints any debugging information in > resolveEntity() method. If you could point out the error, that would be > great help. > > Here is code I am using for the same: > > public void validateTheDocument() { > try{ > String parserName = "org.apache.xerces.parsers.SAXParser"; > XMLReader parser = XMLReaderFactory.createXMLReader(parserName); > parser.setFeature("http://xml.org/sax/features/validation", true); > parser.setFeature( > "http://apache.org/xml/features/validation/schema",true ); > > parser.setFeature("http://apache.org/xml/features/validation/schema-full-che > cking", true); > > parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error > ", true); > ErrorHandler defaultHandler = new SAXErrorHandler(); > SchemaResolver resolver = new SchemaResolver(); > parser.setEntityResolver(resolver); > parser.setErrorHandler(defaultHandler); > InputSource source = new InputSource(UserCompany.getDestinationFile()); > System.out.println("the destination file is " + > UserCompany.getDestinationFile()); > parser.parse(source); > > } catch (SAXNotSupportedException ex) > { > } catch (SAXException e) > { > } catch (IOException i ) > { > } > > And here is my SchemaResolver class: > > public class SchemaResolver implements EntityResolver > > { > public SchemaResolver() > { > } > > public InputSource resolveEntity(String publicId, String systemId) { > System.out.println("the system id is " + systemId); > System.out.println("the public id is " + publicId); > return new InputSource("h://afgi/schema.xsd"); > } > } > > > > > > -Shital Joshi > 732-560-0010 x215 > MFG Systems > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]