David Siefert wrote:
Hi,
I am attempting to validate an XML document with an XML schema using the
xerces-c 2.8.0 API. I do roughly the following:
<code>
XercesDOMParser parser = new XercesDOMParser();
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setExternalSchemaLocation(XMLString::transcode("urn:thenamespace
path\\to\\the\\schema.xsd"));
This is a memory leak. You need to free the pointer return by
XMLString::transcode().
const char* xmlFile = "path\\to\\xml\\document\\with\\invalid\\element.xml";
parser->parse(xmlFile);
</code>
I am able to query through the document nodes without any exception being
thrown. But the document contains an element not defined by the schema. Am I
forgetting a step somewhere?
You need to install an ErrorHandler to detect errors. If you want to
stop parsing, you can throw an exception from your ErrorHandler.
Dave