当前位置: 首页>>代码示例>>C++>>正文


C++ ErrorHandler::getSawErrors方法代码示例

本文整理汇总了C++中ErrorHandler::getSawErrors方法的典型用法代码示例。如果您正苦于以下问题:C++ ErrorHandler::getSawErrors方法的具体用法?C++ ErrorHandler::getSawErrors怎么用?C++ ErrorHandler::getSawErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ErrorHandler的用法示例。


在下文中一共展示了ErrorHandler::getSawErrors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: catch

bool VART::XmlBase::ParseFile(const std::string& fileName)
{
    static XercesDOMParser::ValSchemes ValScheme = XercesDOMParser::Val_Auto; //Val_Never Val_Always
    bool bDoNamespaces       = false;
    bool bDoSchema           = false;
    bool bSchemaFullChecking = false;
    bool bDoCreate           = false;
    ErrorHandler* errorHPtr;

    try
    {
        XMLPlatformUtils::Initialize();
    }
    catch(const XMLException &toCatch)
    {
        cerr << "Error during Xerces-c Initialization.\n"
            << "  Exception message:"
            << TempCString(toCatch.getMessage()) << endl;
        return false;
    }

    if (parserPtr)
        delete parserPtr;

    parserPtr = new XercesDOMParser;
    parserPtr->setValidationScheme(ValScheme);
    parserPtr->setDoNamespaces(bDoNamespaces);
    parserPtr->setDoSchema(bDoSchema);
    parserPtr->setValidationSchemaFullChecking(bSchemaFullChecking);
    parserPtr->setCreateEntityReferenceNodes(bDoCreate);


    // Create the error handler and install it
    errorHPtr = new ErrorHandler;
    parserPtr->setErrorHandler(errorHPtr);

    //  Parse the XML file, catching any XML exceptions that might propogate
    //  out of it.
    try
    {
        parserPtr->parse(fileName.c_str());
    }
    catch (const OutOfMemoryException&)
    {
        cerr << "OutOfMemoryException" << endl;
        delete errorHPtr;
        return false;
    }
    catch (const XMLException& e)
    {
        cerr << "An error occurred during parsing\n   Message: "
             << TempCString(e.getMessage()) << endl;
        delete errorHPtr;
        return false;
    }
    catch (const DOMException& e)
    {
        const unsigned int maxChars = 2047;
        XMLCh errText[maxChars + 1];

        cerr << "\nDOM Error during parsing: '" << fileName << "'\n"
             << "DOMException code is:  " << e.code << endl;
        if (DOMImplementation::loadDOMExceptionMsg(e.code, errText, maxChars))
             cerr << "Message is: " << TempCString(errText) << endl;
        delete errorHPtr;
        return false;
    }
    catch (...)
    {
        cerr << "An error occurred during parsing\n " << endl;
        delete errorHPtr;
        return false;
    }
    if (errorHPtr->getSawErrors())
    {
        //  Clean up the error handler. The parser does not adopt handlers
        //  since they could be many objects or one object installed for multiple
        //  handlers.
        delete errorHPtr;
        return false;
    }
    else
    {
        //...clean up the error handler. The parser does not adopt handlers
        //  since they could be many objects or one object installed for multiple
        //  handlers.
        delete errorHPtr;

        // Since parsing was sucessful, intialize the document pointer, i.e.:
        // extract the DOM tree, get the list of all the elements.
        documentPtr = parserPtr->getDocument();
        return true;
    }
}
开发者ID:haschmitt,项目名称:iV-ART,代码行数:94,代码来源:xmlbase.cpp


注:本文中的ErrorHandler::getSawErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。