validating an xml file using sax parser 2003-04-29 - By Shital Joshi
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: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|