本文整理汇总了C++中SAX2XMLReader::loadGrammar方法的典型用法代码示例。如果您正苦于以下问题:C++ SAX2XMLReader::loadGrammar方法的具体用法?C++ SAX2XMLReader::loadGrammar怎么用?C++ SAX2XMLReader::loadGrammar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SAX2XMLReader
的用法示例。
在下文中一共展示了SAX2XMLReader::loadGrammar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isValid
bool XMLValidator::isValid(const String & filename, const String & schema, std::ostream & os)
{
filename_ = filename;
os_ = &os;
//try to open file
if (!File::exists(filename))
{
throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
}
// initialize parser
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException & toCatch)
{
throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "", String("Error during initialization: ") + Internal::StringManager().convert(toCatch.getMessage()));
}
SAX2XMLReader * parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, false);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
//set this class as error handler
parser->setErrorHandler(this);
parser->setContentHandler(NULL);
parser->setEntityResolver(NULL);
//load schema
LocalFileInputSource schema_file(Internal::StringManager().convert(schema));
parser->loadGrammar(schema_file, Grammar::SchemaGrammarType, true);
parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
// try to parse file
LocalFileInputSource source(Internal::StringManager().convert(filename.c_str()));
try
{
parser->parse(source);
delete(parser);
}
catch (...)
{
/// nothing to do here
}
return valid_;
}
示例2: main
//.........这里部分代码省略.........
// the input is a list file
if (doList)
fin.open(argV[argInd]);
if (fin.fail()) {
XERCES_STD_QUALIFIER cerr <<"Cannot open the list file: " << argV[argInd] << XERCES_STD_QUALIFIER endl;
return 3;
}
while (more)
{
char fURI[1000];
//initialize the array to zeros
memset(fURI,0,sizeof(fURI));
if (doList) {
if (! fin.eof() ) {
fin.getline (fURI, sizeof(fURI));
if (!*fURI)
continue;
else {
xsdFile = fURI;
XERCES_STD_QUALIFIER cerr << "==Parsing== " << xsdFile << XERCES_STD_QUALIFIER endl;
}
}
else
break;
}
else {
xsdFile = argV[argInd];
more = false;
}
parser->loadGrammar(xsdFile, Grammar::SchemaGrammarType, true);
if (handler.getSawErrors())
{
handler.resetErrors();
}
else
{
parsedOneSchemaOkay = true;
}
}
if (parsedOneSchemaOkay)
{
XERCES_STD_QUALIFIER cout << "********** Printing out information from Schema **********" << "\n\n";
bool updatedXSModel;
XSModel *xsModel = grammarPool->getXSModel(updatedXSModel);
if (xsModel)
{
StringList *namespaces = xsModel->getNamespaces();
for (unsigned i = 0; i < namespaces->size(); i++) {
XERCES_STD_QUALIFIER cout << "Processing Namespace: ";
const XMLCh *nameSpace = namespaces->elementAt(i);
if (nameSpace && *nameSpace)
XERCES_STD_QUALIFIER cout << StrX(nameSpace);
XERCES_STD_QUALIFIER cout << "\n============================================" << XERCES_STD_QUALIFIER endl << XERCES_STD_QUALIFIER endl;
processElements(xsModel->getComponentsByNamespace(XSConstants::ELEMENT_DECLARATION,
nameSpace));
processTypeDefinitions(xsModel->getComponentsByNamespace(XSConstants::TYPE_DEFINITION,
nameSpace));
}
}