-->

Validating document in Xerces C++

2020-02-16 03:48发布

问题:

I want to load an XML document in Xerces-C++ (version 2.8, under Linux), and validate it using a DTD schema not referenced from the document. I tried the following:

XercesDOMParser parser;
parser.loadGrammar("grammar.dtd", Grammar::DTDGrammarType);
parser.setValidationScheme(XercesDOMParser::Val_Always);
parser.parse("xmlfile.xml");

But it doesn't indicate an error if the document is not valid. What am I missing?

回答1:

You'll need to set an error handler before calling parse if you want to see anything:

Handler handler;    
parser.setErrorHandler( &handler );

where Handler is a class derived from ErrorHandler