You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by David Siefert <si...@yahoo.com> on 2008/08/26 22:48:00 UTC
Validation with 2.8.0 not working as documented.
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"));
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?
Thanks,
David
Re: Validation with 2.8.0 not working as documented.
Posted by David Bertoni <db...@apache.org>.
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