Hello folks,
I'm trying to get Xerces-C 2.7.0 to validate my XML documents, however I
don't have much luck.
Here is what I do:
---- (from main.cpp)
[... initialization ...]
SchemaValidator* validator = new SchemaValidator();
XercesDOMParser* parser = new XercesDOMParser(validator);
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true); // optional
parser->setDoSchema(true);
std::string externalSchemaLocation;
externalSchemaLocation = "http://foo.com/foo foo.xsd";
if(externalSchemaLocation.size() != 0)
parser->setExternalSchemaLocation(externalSchemaLocation.c_str());
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
XMLErrorReporter* errorReporter = new MyReporter();
validator->setErrorReporter(errorReporter);
try {
parser->parse("foo.xml");
} catch(const SAXParseException& ex){
[...]
----
The error handler simply implements the XMLErrorReporter interface,
however, none of it's methods were called.
I validate foo.xml against foo.xsd, which defines the namespace
http://foo.com/foo. The foo.xsd file is in the working directory of my
executable.
When I run the code above, xerces finds no errors, however, if you look
at the schema file, foo.xml doesn't comply to the schema defined for
it's namespace.
Any clues what I did wrong here?
Thanks a lot in advance,
Uwe
P.S.: The XML files...
The XML/XSD files look like this:
---- (foo.xsd)
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://foo.com/foo"
targetNamespace="http://foo.com/foo">
<xs:complexType name="Foo">
<xs:attribute name="value" type="xs:int"/>
</xs:complexType>
<xs:element name="foo" type="Foo"/>
</xs:schema>
---- (foo.xml)
<?xml version='1.0' encoding='UTF-8'?>
<bar xmlns="http://foo.com/foo" value='1'>
<oof/>
</bar>