xerces-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bovy, Stephen J" <STEPHEN.B...@ca.com>
Subject RE: Parser not failing on bad schema?
Date Wed, 07 Apr 2004 00:18:34 GMT
I don't know, I am a beginer just like you , 

The samples seem to use a lot of try catch logic like this :

Which seems to imply  that an exception will be thrown,  
but you need to code a try/catch to catch that "exception".


try                                                             
{                                                               
    // reset document pool                                      
    parser->resetDocumentPool();                        
    doc = sstate->parser->parseURI(xmlFile);      
}                                                               
catch (const XMLException& toCatch)                             
{                                                               
   cerr << "\nError during parsing: '" << xmlFile << "'\n"     
       << "Exception message is:  \n"                         
       << StrX(toCatch.getMessage()) << "\n" << endl;         
                                                      
}                                                               
catch (const DOMException& toCatch)                             
{                                                               
    const unsigned int maxChars = 2047;                         
    XMLCh errText maxChars + 1 ;                                
                                                                
  cerr << "\nDOM Error during parsing: '" << xmlFile << "'\n" 
       << "DOMException code is:  " << toCatch.code << endl;  
                                                                
    if (DOMImplementation::loadDOMExceptionMsg(                 
                           toCatch.code, errText, maxChars))    
       cerr << "Message is: " << StrX(errText) << endl;
}       
catch (...)                                                       
{                                                                 
 // cerr << "\nUnexpected exception during parsing: '" <<         
 //      xmlFile << "'\n";                                        
    hcsRet->code = 18;                                            
    hcsRet->reas = 4;                                             	
    throw 18;                                                     
}                                                                 
                                                                  
if (errorHandler.getSawErrors())                          
{                                                                 
 // cerr << "\nErrors occurred, no output available\n" << endl;   
    hcsRet->code = 18;                                            
    hcsRet->reas = 5;                                             
    throw 18;                                                     
}                                                                  

The interesting thing in the sample code that I cut and pasted into my
app
is that the error-handler sets an error-flag which is then tested in :

      errorHandler.getSawErrors()

But, you ask some very good questions (which I agree deserve an answer )


-----Original Message-----
From: Nick Bastin [mailto:nbastin@opnet.com] 
Sent: Tuesday, April 06, 2004 4:44 PM
To: xerces-c-dev@xml.apache.org
Subject: Re: Parser not failing on bad schema?


On Apr 6, 2004, at 6:08 PM, Bovy, Stephen J wrote:

> You forgot to set the error handler, at least , its not in the code 
> snippet you posted.

Ok, well, I did set the error handler, I just didn't include the code
for that.  That was supposed to be inferred from my comment that the
error handler reports no errors, but I probably should have been more
explicit.  Is the error handler the only way to get an indication that
the validation failed?  My thought was that a NULL DOMDocument should be
returned, or an exception should be thrown...  (Or there'd be some API
on DOMDocument to ask if it was valid)

--
Nick


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Mime
View raw message