Hi Simon,

Looks like you're running into the common problem that people don't realize
that SAX DefaultHandler provides an empty implementation of the SAX
ErrorHandler interface.  So the parser can report all the errors it wants
and you'll be none the wiser.

Cheers,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  [EMAIL PROTECTED]




|---------+------------------------------>
|         |           "Simon White"      |
|         |           <[EMAIL PROTECTED]|
|         |           pharma.com>        |
|         |                              |
|         |           06/25/2003 08:24 AM|
|         |           Please respond to  |
|         |           xerces-j-user      |
|         |                              |
|---------+------------------------------>
  
>---------------------------------------------------------------------------------------------------------------------------------------------|
  |                                                                             
                                                                |
  |       To:       <[EMAIL PROTECTED]>                                         
                                                     |
  |       cc:                                                                   
                                                                |
  |       Subject:  Validating with SAX Problem                                 
                                                                |
  |                                                                             
                                                                |
  |                                                                             
                                                                |
  
>---------------------------------------------------------------------------------------------------------------------------------------------|



Hi all,

I'm trying to validate an XML document with a Schema, using SAXParser and
whatever I do, the document validates,
even when the document and schema don't match, i.e. I use a totally
irrelevant schema. Is what I'm doing correct? or even possible?
I can't unfortunately go down the DOM path, as we have memory limits, and
some of the files we need to validate will be rather large.

This is the code I'm using, have I done soemthing outrageously wrong here ?

---------------------------------------------------------
String urlStr = /** the string url of the document I wish to validate **/
String MY_XSD = "http://localhost:8282/my.xsd";;
String SCHEMA_LOCATION = "
http://apache.org/xml/properties/schema/external-schemaLocation";;

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);

SAXParser saxParser = factory.newSAXParser();
XMLReader reader = saxParser.getXMLReader();

reader.setFeature("http://xml.org/sax/features/validation";, true);
reader.setFeature("http://apache.org/xml/features/validation/schema";,
true);
reader.setProperty(SCHEMA_LOCATION, MY_XSD );

saxParser.parse(urlStr, new DefaultHandler());
---------------------------------------------------------------------

Regards

Simon



---------------------------------------------------------------------
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]

Reply via email to