It looks you didn't read my e-mail; I said

"Furthermore, in order to use schema, you should invoke setDoSchema(true)
Finally, change the setExternalSchemaLocation to be setExternalNoNamespaceSchemaLocation (or, if schema.xsd is using a targetNamespace, change the argument of setExternalSchemaLocation to be "uri schema.xsd") "

Alberto

Leif Goodwin ha scritto:
We've tried the above code and it does not validate the XML file. All it does
is check that it is well formed. Here is the hacked code: /* initialize xerces system before usig API: DOM, SAX, SAX2 */ try { xercesc::XMLPlatformUtils::Initialize(); } catch (const XMLException &e) { char *message = XMLString::transcode(e.getMessage()); //qDebug() << "Error during XML initialization: " << message << endl; XMLString::release(&message); //return; } /* actual xerces work */ char *xml_file = "D:\\Development\\Chronicle\\Example Schemas and Form Templates\\DrillData_1.xml"; char *xml_schema = "D:\\Development\\Chronicle\\Example Schemas and Form Templates\\newDrillData.xsd"; SAXParser *parser = new SAXParser();
    CSaxParserErrorHandler errorHandler;
    parser->setErrorHandler(&errorHandler);

//parser->setDoValidation(true); parser->setDoNamespaces(true); try { parser->setExternalSchemaLocation(xml_schema); parser->parse(xml_file); return true; } catch (const XMLException &e) { char *message = XMLString::transcode(e.getMessage()); //qDebug() << "XML Exception is: " << message << endl; XMLString::release(&message); } catch(...) { //qDebug() << "XML Unexpected exception" << endl; } delete parser; //delete doc_handler; /* terminate and cleanup */ XMLPlatformUtils::Terminate();
The XML file purposefully has an extra element which is not allowed by the
schema. But the parser accepts it. Here is the quickly knocked together error handler:
class CSaxParserErrorHandler : public xercesc_3_0::ErrorHandler
{
    virtual void warning(const SAXParseException& exc);
    virtual void error(const SAXParseException& exc);
    virtual void fatalError(const SAXParseException& exc);
    void resetErrors()
    {
    }

};

void CSaxParserErrorHandler::warning(const SAXParseException& exc)
{
    CReport::Warning(
        "File: %s, line %d, column %d : %s",
StrX(exc.getSystemId()), (int)exc.getLineNumber(),
        (int)exc.getLineNumber(),
        StrX(exc.getMessage()));
}

void CSaxParserErrorHandler::error(const SAXParseException& exc)
{
    CReport::Error(
        "File: %s, line %d, column %d : %s",
StrX(exc.getSystemId()), (int)exc.getLineNumber(),
        (int)exc.getLineNumber(),
        StrX(exc.getMessage()));
}

void CSaxParserErrorHandler::fatalError(const SAXParseException& exc)
{
    CReport::Error(
        "(Fatal Error) File: %s, line %d, column %d : %s",
StrX(exc.getSystemId()), (int)exc.getLineNumber(),
        (int)exc.getLineNumber(),
        StrX(exc.getMessage()));
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to