Hi xerces users.
I have a (hopefully) easy question for you experts out there.
I would like to validate my xml file against an xml schema.
The parser complains if my xml is ill-formed but does not validate against
the schema I embedded into the xml. I tried to provide an external
location explicitly but it makes no difference.
(this should be pretty standard, but I can't figure it out...)

I use the following code:

    XMLPlatformUtils::Initialize();
    XercesDOMParser* parser = new XercesDOMParser();
    parser->setValidationScheme(XercesDOMParser::Val_Always);
    parser->setDoSchema(true);
    parser->setDoNamespaces(true);
    parser->setExternalSchemaLocation(schema.c_str());
    parser->loadGrammar(schema.c_str(), Grammar::SchemaGrammarType, true);
    parser->setSkipDTDValidation(false);
    ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
    parser->setErrorHandler(errHandler);
    const char* xmlFile = xmloutFN.c_str();
    try{
      parser->parse(xmloutFN.c_str());
    }

where:
"schema" is a string in the form "myNamespace /home/myHome/schema.xsd"
"xmloutFN" ia a string in the form "/home/myHome/toValidate.xml"

I read older posts and this seems to be what people did there. And it
seemed to work fine for them.
??

Side question: in case I do provoke errors on purpose (giving a non
well-formed xml file), the best I was able to do was to dereferenciate the
xercesc_3_1::SAXParseException.getMessage() which is most uninformative (I
get a most uninformative integer value). Any suggestions here?

Thank you for your help and patience!

Mattia

Reply via email to