/* Read the file. */ bool GQCFileData::Read(const std::string &fileName) { Clear(); // Initialize the XML4C2 system try { XMLPlatformUtils::Initialize(); } catch (const XMLException&) { return false; } bool status = false; SAXParser* parser = new SAXParser; parser->setValidationScheme(SAXParser::Val_Never); parser->setLoadExternalDTD(false); parser->setDoNamespaces(false); parser->setDoSchema(false); parser->setValidationSchemaFullChecking(false); SAXGenericReportHandlers handler(this); parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); try { parser->parse(fileName.c_str()); int errorCount = parser->getErrorCount(); if (errorCount == 0) { status = true; } } catch (...) { status = false; } delete parser; XMLPlatformUtils::Terminate(); return status; }
// --------------------------------------------------------------------------- // Program entry point // --------------------------------------------------------------------------- int main(int argC, char* argV[]) { // Initialize the XML4C system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return 1; } int parmInd; for (parmInd = 1; parmInd < argC; parmInd++) { // Break out on first parm not starting with a dash if (argV[parmInd][0] != '-') break; // Watch for special case help request if (!strcmp(argV[parmInd], "-?")) { usage(); XMLPlatformUtils::Terminate(); return 2; } else if (!strncmp(argV[parmInd], "-v=", 3) || !strncmp(argV[parmInd], "-V=", 3)) { const char* const parm = &argV[parmInd][3]; if (!strcmp(parm, "never")) valScheme = SAXParser::Val_Never; else if (!strcmp(parm, "auto")) valScheme = SAXParser::Val_Auto; else if (!strcmp(parm, "always")) valScheme = SAXParser::Val_Always; else { XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl; XMLPlatformUtils::Terminate(); return 2; } } else if (!strcmp(argV[parmInd], "-n") || !strcmp(argV[parmInd], "-N")) { doNamespaces = true; } else if (!strcmp(argV[parmInd], "-s") || !strcmp(argV[parmInd], "-S")) { doSchema = true; } else if (!strcmp(argV[parmInd], "-f") || !strcmp(argV[parmInd], "-F")) { schemaFullChecking = true; } else { XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd] << "', ignoring it\n" << XERCES_STD_QUALIFIER endl; } } // // Create a SAX parser object. Then, according to what we were told on // the command line, set the options. // SAXParser* parser = new SAXParser; parser->setValidationScheme(valScheme); parser->setDoNamespaces(doNamespaces); parser->setDoSchema(doSchema); parser->setValidationSchemaFullChecking(schemaFullChecking); // // Create our SAX handler object and install it on the parser, as the // document and error handler. We are responsible for cleaning them // up, but since its just stack based here, there's nothing special // to do. // StdInParseHandlers handler; parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); unsigned long duration; int errorCount = 0; // create a faux scope so that 'src' destructor is called before // XMLPlatformUtils::Terminate { // // Kick off the parse and catch any exceptions. Create a standard // input input source and tell the parser to parse from that. // StdInInputSource src; try { const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); parser->parse(src); const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); duration = endMillis - startMillis; errorCount = parser->getErrorCount(); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCount = 2; return 4; } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n" << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCount = 1; return 4; } // Print out the stats that we collected and time taken if (!errorCount) { XERCES_STD_QUALIFIER cout << StrX(src.getSystemId()) << ": " << duration << " ms (" << handler.getElementCount() << " elems, " << handler.getAttrCount() << " attrs, " << handler.getSpaceCount() << " spaces, " << handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; } } // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; XMLPlatformUtils::Terminate(); if (errorCount > 0) return 4; else return 0; }
void process(char* const xmlFile) { // // Create a Schema validator to be used for our validation work. Then create // a SAX parser object and pass it our validator. Then, according to what // we were told on the command line, set it to validate or not. He owns // the validator, so we have to allocate it. // SAXParser parser; parser.setValidationScheme(SAXParser::Val_Always); parser.setDoNamespaces(true); parser.setDoSchema(true); parser.parse(xmlFile); if (parser.getErrorCount()) { XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl; return; } if (!parser.getValidator().handlesSchema()) { XERCES_STD_QUALIFIER cout << "\n Non schema document, no output available\n" << XERCES_STD_QUALIFIER endl; return; } Grammar* rootGrammar = parser.getRootGrammar(); if (!rootGrammar || rootGrammar->getGrammarType() != Grammar::SchemaGrammarType) { XERCES_STD_QUALIFIER cout << "\n Non schema grammar, no output available\n" << XERCES_STD_QUALIFIER endl; return; } // // Now we will get an enumerator for the element pool from the validator // and enumerate the elements, printing them as we go. For each element // we get an enumerator for its attributes and print them also. // SchemaGrammar* grammar = (SchemaGrammar*) rootGrammar; RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = grammar->getElemEnumerator(); if (!elemEnum.hasMoreElements()) { XERCES_STD_QUALIFIER cout << "\nThe validator has no elements to display\n" << XERCES_STD_QUALIFIER endl; return; } while(elemEnum.hasMoreElements()) { const SchemaElementDecl& curElem = elemEnum.nextElement(); // Name XERCES_STD_QUALIFIER cout << "Name:\t\t\t" << StrX(curElem.getFullName()) << "\n"; // Model Type XERCES_STD_QUALIFIER cout << "Model Type:\t\t"; switch( curElem.getModelType() ) { case SchemaElementDecl::Empty: XERCES_STD_QUALIFIER cout << "Empty"; break; case SchemaElementDecl::Any: XERCES_STD_QUALIFIER cout << "Any"; break; case SchemaElementDecl::Mixed_Simple: XERCES_STD_QUALIFIER cout << "Mixed_Simple"; break; case SchemaElementDecl::Mixed_Complex: XERCES_STD_QUALIFIER cout << "Mixed_Complex"; break; case SchemaElementDecl::Children: XERCES_STD_QUALIFIER cout << "Children"; break; case SchemaElementDecl::Simple: XERCES_STD_QUALIFIER cout << "Simple"; break; case SchemaElementDecl::ElementOnlyEmpty: XERCES_STD_QUALIFIER cout << "ElementOnlyEmpty"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Create Reason XERCES_STD_QUALIFIER cout << "Create Reason:\t"; switch( curElem.getCreateReason() ) { case XMLElementDecl::NoReason: XERCES_STD_QUALIFIER cout << "Empty"; break; case XMLElementDecl::Declared: XERCES_STD_QUALIFIER cout << "Declared"; break; case XMLElementDecl::AttList: XERCES_STD_QUALIFIER cout << "AttList"; break; case XMLElementDecl::InContentModel: XERCES_STD_QUALIFIER cout << "InContentModel"; break; case XMLElementDecl::AsRootElem: XERCES_STD_QUALIFIER cout << "AsRootElem"; break; case XMLElementDecl::JustFaultIn: XERCES_STD_QUALIFIER cout << "JustFaultIn"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Content Spec Node processContentSpecNode( curElem.getContentSpec() ); // Misc Flags int mflags = curElem.getMiscFlags(); if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "Misc. Flags:\t"; } if ( mflags & SchemaSymbols::XSD_NILLABLE ) XERCES_STD_QUALIFIER cout << "Nillable "; if ( mflags & SchemaSymbols::XSD_ABSTRACT ) XERCES_STD_QUALIFIER cout << "Abstract "; if ( mflags & SchemaSymbols::XSD_FIXED ) XERCES_STD_QUALIFIER cout << "Fixed "; if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "\n"; } // Substitution Name SchemaElementDecl* subsGroup = curElem.getSubstitutionGroupElem(); if( subsGroup ) { const XMLCh* uriText = parser.getURIText(subsGroup->getURI()); XERCES_STD_QUALIFIER cout << "Substitution Name:\t" << StrX(uriText) << "," << StrX(subsGroup->getBaseName()) << "\n"; } // Content Model const XMLCh* fmtCntModel = curElem.getFormattedContentModel(); if( fmtCntModel != NULL ) { XERCES_STD_QUALIFIER cout << "Content Model:\t" << StrX(fmtCntModel) << "\n"; } const ComplexTypeInfo* ctype = curElem.getComplexTypeInfo(); if( ctype != NULL) { XERCES_STD_QUALIFIER cout << "ComplexType:\n"; XERCES_STD_QUALIFIER cout << "\tTypeName:\t" << StrX(ctype->getTypeName()) << "\n"; ContentSpecNode* cSpecNode = ctype->getContentSpec(); processContentSpecNode(cSpecNode, true ); } // Datatype DatatypeValidator* dtValidator = curElem.getDatatypeValidator(); processDatatypeValidator( dtValidator ); // Get an enumerator for this guy's attributes if any if ( curElem.hasAttDefs() ) { processAttributes( curElem.getAttDefList() ); } XERCES_STD_QUALIFIER cout << "--------------------------------------------"; XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; } return; }
// --------------------------------------------------------------------------- // Program entry point // --------------------------------------------------------------------------- int main(int argC, char* argV[]) { // Initialize the XML4C system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return 1; } // Check command line and extract arguments. if (argC < 2) { usage(); XMLPlatformUtils::Terminate(); return 1; } // We only have one required parameter, which is the file to process if ((argC != 2) || (*(argV[1]) == '-')) { usage(); XMLPlatformUtils::Terminate(); return 1; } const char* xmlFile = argV[1]; SAXParser::ValSchemes valScheme = SAXParser::Val_Auto; // // Create a DTD validator to be used for our validation work. Then create // a SAX parser object and pass it our validator. Then, according to what // we were told on the command line, set it to validate or not. He owns // the validator, so we have to allocate it. // int errorCount = 0; DTDValidator* valToUse = new DTDValidator; SAXParser* parser = new SAXParser(valToUse); parser->setValidationScheme(valScheme); // // Get the starting time and kick off the parse of the indicated // file. Catch any exceptions that might propogate out of it. // int errorCode = 0; try { parser->parse(xmlFile); errorCount = parser->getErrorCount(); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCode = 5; } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n" << "Exception message is: \n" << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCode = 4; } if(errorCode) { XMLPlatformUtils::Terminate(); return errorCode; } if (!errorCount) { // // Now we will get an enumerator for the element pool from the validator // and enumerate the elements, printing them as we go. For each element // we get an enumerator for its attributes and print them also. // DTDGrammar* grammar = (DTDGrammar*) valToUse->getGrammar(); NameIdPoolEnumerator<DTDElementDecl> elemEnum = grammar->getElemEnumerator(); if (elemEnum.hasMoreElements()) { XERCES_STD_QUALIFIER cout << "\nELEMENTS:\n----------------------------\n"; while(elemEnum.hasMoreElements()) { const DTDElementDecl& curElem = elemEnum.nextElement(); XERCES_STD_QUALIFIER cout << " Name: " << StrX(curElem.getFullName()) << "\n"; XERCES_STD_QUALIFIER cout << " Content Model: " << StrX(curElem.getFormattedContentModel()) << "\n"; // Get an enumerator for this guy's attributes if any if (curElem.hasAttDefs()) { XERCES_STD_QUALIFIER cout << " Attributes:\n"; XMLAttDefList& attList = curElem.getAttDefList(); for (unsigned int i=0; i<attList.getAttDefCount(); i++) { const XMLAttDef& curAttDef = attList.getAttDef(i); XERCES_STD_QUALIFIER cout << " Name:" << StrX(curAttDef.getFullName()) << ", Type: "; // Get the type and display it const XMLAttDef::AttTypes type = curAttDef.getType(); switch(type) { case XMLAttDef::CData : XERCES_STD_QUALIFIER cout << "CDATA"; break; case XMLAttDef::ID : XERCES_STD_QUALIFIER cout << "ID"; break; case XMLAttDef::IDRef : case XMLAttDef::IDRefs : XERCES_STD_QUALIFIER cout << "IDREF(S)"; break; case XMLAttDef::Entity : case XMLAttDef::Entities : XERCES_STD_QUALIFIER cout << "ENTITY(IES)"; break; case XMLAttDef::NmToken : case XMLAttDef::NmTokens : XERCES_STD_QUALIFIER cout << "NMTOKEN(S)"; break; case XMLAttDef::Notation : XERCES_STD_QUALIFIER cout << "NOTATION"; break; case XMLAttDef::Enumeration : XERCES_STD_QUALIFIER cout << "ENUMERATION"; break; default: break; } XERCES_STD_QUALIFIER cout << "\n"; } } XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; } } else { XERCES_STD_QUALIFIER cout << "The validator has no elements to display\n" << XERCES_STD_QUALIFIER endl; } } else XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl; // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; // And call the termination method XMLPlatformUtils::Terminate(); if (errorCount > 0) return 4; else return 0; }
// --------------------------------------------------------------------------- // Program entry point // --------------------------------------------------------------------------- int main(int argc, char* args[]) { // Initialize the XML4C system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return 1; } // We only have one parameter, which is the file to process // We only have one required parameter, which is the file to process if ((argc != 2) || (*(args[1]) == '-')) { usage(); XMLPlatformUtils::Terminate(); return 1; } const char* xmlFile = args[1]; // // Create a SAX parser object. Then, according to what we were told on // the command line, set it to validate or not. // SAXParser* parser = new SAXParser; // // Create our SAX handler object and install it on the parser, as the // document, entity and error handlers. // RedirectHandlers handler; parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); parser->setEntityResolver(&handler); // // Get the starting time and kick off the parse of the indicated file. // Catch any exceptions that might propogate out of it. // unsigned long duration; int errorCount = 0; int errorCode = 0; try { const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); parser->parse(xmlFile); const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); duration = endMillis - startMillis; errorCount = parser->getErrorCount(); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCode = 5; } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << xmlFile << "'\n" << "Exception message is: \n" << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCode = 4; } if(errorCode) { XMLPlatformUtils::Terminate(); return errorCode; } // Print out the stats that we collected and time taken. if (!errorCount) { XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms (" << handler.getElementCount() << " elems, " << handler.getAttrCount() << " attrs, " << handler.getSpaceCount() << " spaces, " << handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; } // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; XMLPlatformUtils::Terminate(); if (errorCount > 0) return 4; else return 0; }
// --------------------------------------------------------------------------- // Program entry point // --------------------------------------------------------------------------- int main(int argC, char* argV[]) { // Initialize the XML4C2 system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return 1; } SAXParser::ValSchemes valScheme = SAXParser::Val_Auto; bool doNamespaces = false; bool doSchema = false; bool schemaFullChecking = false; int argInd; for (argInd = 1; argInd < argC; argInd++) { // Break out on first parm not starting with a dash if (argV[argInd][0] != '-') { usage(); XMLPlatformUtils::Terminate(); return 1; } // Watch for special case help request if (!strcmp(argV[argInd], "-?")) { usage(); XMLPlatformUtils::Terminate(); return 1; } else if (!strncmp(argV[argInd], "-v=", 3) || !strncmp(argV[argInd], "-V=", 3)) { const char* const parm = &argV[argInd][3]; if (!strcmp(parm, "never")) valScheme = SAXParser::Val_Never; else if (!strcmp(parm, "auto")) valScheme = SAXParser::Val_Auto; else if (!strcmp(parm, "always")) valScheme = SAXParser::Val_Always; else { XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl; return 2; } } else if (!strcmp(argV[argInd], "-n") || !strcmp(argV[argInd], "-N")) { doNamespaces = true; } else if (!strcmp(argV[argInd], "-s") || !strcmp(argV[argInd], "-S")) { doSchema = true; } else if (!strcmp(argV[argInd], "-f") || !strcmp(argV[argInd], "-F")) { schemaFullChecking = true; } else { XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[argInd] << "', ignoring it\n" << XERCES_STD_QUALIFIER endl; } } // // Create a SAX parser object. Then, according to what we were told on // the command line, set it to validate or not. // SAXParser* parser = new SAXParser; parser->setValidationScheme(valScheme); parser->setDoNamespaces(doNamespaces); parser->setDoSchema(doSchema); parser->setValidationSchemaFullChecking(schemaFullChecking); // // Create our SAX handler object and install it on the parser, as the // document and error handlers. // MemParseHandlers handler; parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); // // Create MemBufferInputSource from the buffer containing the XML // statements. // // NOTE: We are using strlen() here, since we know that the chars in // our hard coded buffer are single byte chars!!! The parameter wants // the number of BYTES, not chars, so when you create a memory buffer // give it the byte size (which just happens to be the same here.) // MemBufInputSource* memBufIS = new MemBufInputSource ( (const XMLByte*)gXMLInMemBuf , strlen(gXMLInMemBuf) , gMemBufId , false ); // // Get the starting time and kick off the parse of the indicated // file. Catch any exceptions that might propogate out of it. // unsigned long duration; int errorCount = 0; int errorCode = 0; try { const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); parser->parse(*memBufIS); const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); duration = endMillis - startMillis; errorCount = parser->getErrorCount(); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCode = 5; } catch (const XMLException& e) { XERCES_STD_QUALIFIER cerr << "\nError during parsing memory stream:\n" << "Exception message is: \n" << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCode = 4; } if(errorCode) { XMLPlatformUtils::Terminate(); return errorCode; } // Print out the stats that we collected and time taken. if (!errorCount) { XERCES_STD_QUALIFIER cout << "\nFinished parsing the memory buffer containing the following " << "XML statements:\n\n" << gXMLInMemBuf << "\n\n\n" << "Parsing took " << duration << " ms (" << handler.getElementCount() << " elements, " << handler.getAttrCount() << " attributes, " << handler.getSpaceCount() << " spaces, " << handler.getCharacterCount() << " characters).\n" << XERCES_STD_QUALIFIER endl; } // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; delete memBufIS; // And call the termination method XMLPlatformUtils::Terminate(); if (errorCount > 0) return 4; else return 0; }
// --------------------------------------------------------------------------- // Program entry point // --------------------------------------------------------------------------- int main(int argC, char* argV[]) { // Initialize the XML4C system try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n" << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; return 1; } // Check command line and extract arguments. if (argC < 2) { usage(); XMLPlatformUtils::Terminate(); return 1; } // See if non validating dom parser configuration is requested. int parmInd; for (parmInd = 1; parmInd < argC; parmInd++) { // Break out on first parm not starting with a dash if (argV[parmInd][0] != '-') break; // Watch for special case help request if (!strcmp(argV[parmInd], "-?")) { usage(); XMLPlatformUtils::Terminate(); return 2; } else if (!strncmp(argV[parmInd], "-v=", 3) || !strncmp(argV[parmInd], "-V=", 3)) { const char* const parm = &argV[parmInd][3]; if (!strcmp(parm, "never")) valScheme = SAXParser::Val_Never; else if (!strcmp(parm, "auto")) valScheme = SAXParser::Val_Auto; else if (!strcmp(parm, "always")) valScheme = SAXParser::Val_Always; else { XERCES_STD_QUALIFIER cerr << "Unknown -v= value: " << parm << XERCES_STD_QUALIFIER endl; XMLPlatformUtils::Terminate(); return 2; } } else if (!strcmp(argV[parmInd], "-n") || !strcmp(argV[parmInd], "-N")) { doNamespaces = true; } else if (!strcmp(argV[parmInd], "-s") || !strcmp(argV[parmInd], "-S")) { doSchema = true; } else if (!strcmp(argV[parmInd], "-f") || !strcmp(argV[parmInd], "-F")) { schemaFullChecking = true; } else { XERCES_STD_QUALIFIER cerr << "Unknown option '" << argV[parmInd] << "', ignoring it\n" << XERCES_STD_QUALIFIER endl; } } // // And now we have to have only one parameter left and it must be // the file name. // if (parmInd + 1 != argC) { usage(); XMLPlatformUtils::Terminate(); return 1; } xmlFile = argV[parmInd]; int errorCount = 0; // // Create a SAX parser object to use and create our SAX event handlers // and plug them in. // SAXParser* parser = new SAXParser; PParseHandlers handler; parser->setDocumentHandler(&handler); parser->setErrorHandler(&handler); parser->setValidationScheme(valScheme); parser->setDoNamespaces(doNamespaces); parser->setDoSchema(doSchema); parser->setValidationSchemaFullChecking(schemaFullChecking); // // Ok, lets do the progressive parse loop. On each time around the // loop, we look and see if the handler has found what its looking // for. When it does, we fall out then. // unsigned long duration; int errorCode = 0; try { // Create a progressive scan token XMLPScanToken token; const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); if (!parser->parseFirst(xmlFile, token)) { XERCES_STD_QUALIFIER cerr << "scanFirst() failed\n" << XERCES_STD_QUALIFIER endl; XMLPlatformUtils::Terminate(); return 1; } // // We started ok, so lets call scanNext() until we find what we want // or hit the end. // bool gotMore = true; while (gotMore && !parser->getErrorCount()) gotMore = parser->parseNext(token); const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); duration = endMillis - startMillis; errorCount = parser->getErrorCount(); // // Reset the parser-> In this simple progrma, since we just exit // now, its not technically required. But, in programs which // would remain open, you should reset after a progressive parse // in case you broke out before the end of the file. This insures // that all opened files, sockets, etc... are closed. // parser->parseReset(token); } catch (const OutOfMemoryException&) { XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; errorCode = 5; } catch (const XMLException& toCatch) { XERCES_STD_QUALIFIER cerr << "\nAn error occurred: '" << xmlFile << "'\n" << "Exception message is: \n" << StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; errorCode = 4; } if(errorCode) { XMLPlatformUtils::Terminate(); return errorCode; } if (!errorCount) { XERCES_STD_QUALIFIER cout << xmlFile << ": " << duration << " ms (" << handler.getElementCount() << " elems, " << handler.getAttrCount() << " attrs, " << handler.getSpaceCount() << " spaces, " << handler.getCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl; } // // Delete the parser itself. Must be done prior to calling Terminate, below. // delete parser; // And call the termination method XMLPlatformUtils::Terminate(); if (errorCount > 0) return 4; else return 0; }