validate xml against xsd using xerces C++ lib

Joined
May 16, 2011
Messages
3
Reaction score
0
Hi Guys,

I have a problem where i want to validate my xml file against xsd both located at my current working directory. Please have t look to the code snippet below:

XercesDOMParser *domParser = new XercesDOMParser;
LocalFileInputSource fin(X("./sample.xsd"));

domParser->setExternalSchemaLocation(X("./sample.xsd"));

Grammar *gmr = domParser->loadGrammar(fin, Grammar::SchemaGrammarType);

if (gmr == NULL)
{
cerr << "couldn't load schema" << endl;
//return false;
}

ParserErrorHandler errorHandler; //Derived from SetErrorhandler Class

domParser->setErrorHandler(&errorHandler);
domParser->setValidationScheme(XercesDOMParser::Val_Auto);
domParser->setDoNamespaces(true);
domParser->setDoSchema(true);
domParser->setValidationConstraintFatal(true);


domParser->parse("./sample.xml");
cerr << domParser->getErrorCount() << endl;
if (domParser->getErrorCount() == 0)
cerr << "XML file validated against the schema successfully" << endl;
else
cerr << "XML file doesn't conform to the schema" << endl;

when I try to execute above code, i get "couldn't load schema" error message.
I am not getting the exact point of problem here, Is this the way we use DOM Parser to validate xml?
Seems that you have already implemented this logic, please help me in getting out of this error.
It's urgent. Please reply guys.
Thanks a lot in advance.
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top