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 Simon White <Si...@denovopharma.com> on 2003/06/25 14:24:52 UTC

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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


RE: Validating with SAX Problem

Posted by Shital Joshi <sh...@mfgsys.com>.
Hi Simon,

Please find attached Java files. I am doing the same for our application and
it works for me. I am using EntityResolver for schema location.

Thanks,
-Shital Joshi
MFG Systems








-----Original Message-----
From: Simon White [mailto:Simon.White@denovopharma.com]
Sent: Wednesday, June 25, 2003 8:25 AM
To: xerces-j-user@xml.apache.org
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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org