You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jacquet Francois <Ja...@thmulti.com> on 2002/07/04 16:52:51 UTC

SAX2 parser doesn't seem to care of specified schema...

Hi everybody,

here is a problem I've got using SAX2 parser : 
I Implement my own handler (used to build objects from xml files),
derivating from the default handler class, and want all the dirty parsing
job done by the parser according to the schema I provide him, specified in
the xml file. The problem is that the parser doesn't seem to care about the
XML-schema grammar specified in the XML file (see sample) when parsing the
file, but the strange thing is that if I introduce an error in the schema
the parser detects it. So I know that the parser knows the schema, checks
its validity, but it doesn't use it to check the validity of the associated
XML file (for example if I introduce in the XML file an element with a tag
unknown to the schema, the parser doesn't care provided the corresponding
enclosing tag is present!)
My schema and xml file are local.
What is wrong??? why doesn't the parser check tags validity? is it because I
reimplement the contenthandler?
thanks in advance for any help....

Here is my main : 
/////////////////////////
//
//	MAIN (in a class derivating from defaultHandler)
//
////////////////////////
const char * const aFileToParse = "D:/xmlfile.xml";
try {
        XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch) {
        cout << "Error during initialization! :\n"
             << toCatch.getMessage() << "\n";
	}

SAX2XMLReader * p_reader=XMLReaderFactory::createXMLReader();

p_reader->setFeature(XMLString::transcode("http://apache.org/xml/features/va
lidation/schema-full-checking"), true);

p_reader->setContentHandler(this);
p_reader->setErrorHandler(mp_errHandler);// a basic error handler of mine...
try {
	p_reader->parse(aFileToParse );
	}
catch (const XMLException& toCatch) {
        cout << "Error during parsing! :\n"
             << toCatch.getMessage() << "\n";
	}
//////////////////////////

/////////////////////////
//
//	my xml- document : 
//
//////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<StyleFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="D:\docsinfo\XML\StyleFileEssai1.1.xsd">
	<StyleRandomFactors Type="AmbianceChoices">
		........................
	</StyleRandomFactors >
<StyleFile>



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