[ http://nagoya.apache.org/jira/browse/XERCESC-1233?page=history ]
     
Alberto Massari closed XERCESC-1233:
------------------------------------


> Invalid xml for schema does not throw exception?
> ------------------------------------------------
>
>          Key: XERCESC-1233
>          URL: http://nagoya.apache.org/jira/browse/XERCESC-1233
>      Project: Xerces-C++
>         Type: Bug
>   Components: Validating Parser (Schema) (Xerces 1.5 or up only)
>     Versions: 2.5.0
>     Reporter: Michael Hale

>
> The following code seems like it should return -2 when the xml file is not 
> valid for the schema.  However it returns 0.  What do I need to do to find 
> out when an xml file is not valid?
> #include <xercesc/util/PlatformUtils.hpp>
> #include <xercesc/sax2/SAX2XMLReader.hpp>
> #include <xercesc/sax2/XMLReaderFactory.hpp>
> #include <xercesc/sax2/DefaultHandler.hpp>
> XERCES_CPP_NAMESPACE_USE
> int verify (char* xmlFile, char* xmlSchemaPath) {
>       try {
>               XMLPlatformUtils::Initialize();
>       }
>       catch (...) {
>               return -1;
>       }
>       SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
>       parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
>       parser->setFeature(XMLUni::fgXercesSchema, true); 
> //http://apache.org/xml/features/validation/schema
>       parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); 
> //http://apache.org/xml/features/validation/schema-full-checking  
>       parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); 
> //http://xml.org/sax/features/validation
>       parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);
>       parser->setProperty(XMLUni::fgXercesSchemaExternalSchemaLocation, 
> xmlSchemaPath);
>       
> parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, 
> xmlSchemaPath); 
> //http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
>       DefaultHandler* defaultHandler = new DefaultHandler();
>       parser->setContentHandler(defaultHandler);
>       parser->setErrorHandler(defaultHandler);
>       try {
>               parser->parse(xmlFile);
>       }
>       catch (...) {
>               return -2;
>       }
>       delete parser;
>       delete defaultHandler;
>       return 0;
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://nagoya.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


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

Reply via email to