Hi Vikas,

Look at HandlerBase.  I think you'll find its implementation of
ErrorHandler instructive.

Cheers,
Neil
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  [EMAIL PROTECTED]




                                                                                       
                                            
                      "Saraogi, Vikas"                                                 
                                            
                      <[EMAIL PROTECTED]        To:       [EMAIL PROTECTED]            
                                 
                      talone.com>                cc:                                   
                                            
                                                 Subject:  Schema validation using 
Xerces-C++ version 1.6.0?                       
                      02/06/2004 01:52 PM                                              
                                            
                      Please respond to                                                
                                            
                      xerces-c-dev                                                     
                                            
                                                                                       
                                            
                                                                                       
                                            



Hi y'all,


I am trying to do validation of xml files against their schema using the
Xerces library. I am expecting to get an exception while calling
DOMParser::parse method when the xml file is invalid, i.e. it doesn't
conform to its schema, but I don't get any exception. What am I doing
wrong?


Following is snippet of my code:


------------------------------------------------------------------------------

int main(int argc, char* argv[])
{
        try {
                XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
                cout << "Error during initialization! :\n"
                        << DOMString(toCatch.getMessage()) << endl;
                return 1;
        }


        string xml_file = "test.xml";
        bool valid = true;


        try
        {
                DOMParser* parser = new DOMParser;


                parser->setDoNamespaces(true);
                parser->setDoSchema(true);
                parser->setValidationSchemaFullChecking(true);
                parser->setValidationConstraintFatal(true);
                ErrorHandler* errHandler = (ErrorHandler*) new
HandlerBase();
                parser->setErrorHandler(errHandler);


                parser->parse(xml_file.c_str());


                delete errHandler;
                delete parser;
        }
        catch (...) {
                cout << "An error occurred during parsing" << endl;
                valid = false;
        }


        cout << "The xml file is " << ( valid ? "valid" : "invalid" ) <<
endl;

        XMLPlatformUtils::Terminate();


        return 0;
}


------------------------------------------------------------------------------






Thank you for your replies.


Vikas



**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to