saxparser.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,546 行 · 第 1/3 页
CPP
1,546 行
fAdvDHList[index]->endElement(elemDecl, uriId, isRoot, elemPrefix); // // Dump the element depth down again. Don't let it underflow in case // of malformed XML. // if (fElemDepth) fElemDepth--;}void SAXParser::endEntityReference(const XMLEntityDecl& entityDecl){ // // SAX has no way to report this event. But, if there are any installed // advanced handlers, then lets call them with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->endEntityReference(entityDecl);}void SAXParser::ignorableWhitespace(const XMLCh* const chars , const unsigned int length , const bool cdataSection){ // Do not report the whitespace before the root element. if (!fElemDepth) return; // Just map to the SAX document handler if (fDocHandler) fDocHandler->ignorableWhitespace(chars, length); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->ignorableWhitespace(chars, length, cdataSection);}void SAXParser::resetDocument(){ // Just map to the SAX document handler if (fDocHandler) fDocHandler->resetDocument(); // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->resetDocument(); // Make sure our element depth flag gets set back to zero fElemDepth = 0;}void SAXParser::startDocument(){ // Just map to the SAX document handler if (fDocHandler) { fDocHandler->setDocumentLocator(fScanner->getLocator()); fDocHandler->startDocument(); } // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->startDocument();}void SAXParser::startElement( const XMLElementDecl& elemDecl , const unsigned int elemURLId , const XMLCh* const elemPrefix , const RefVectorOf<XMLAttr>& attrList , const unsigned int attrCount , const bool isEmpty , const bool isRoot){ // Bump the element depth counter if not empty if (!isEmpty) fElemDepth++; if (fDocHandler) { fAttrList.setVector(&attrList, attrCount); if (fScanner->getDoNamespaces()) { if (elemPrefix && *elemPrefix) { fElemQNameBuf.set(elemPrefix); fElemQNameBuf.append(chColon); fElemQNameBuf.append(elemDecl.getBaseName()); fDocHandler->startElement(fElemQNameBuf.getRawBuffer(), fAttrList); // If its empty, send the end tag event now if (isEmpty) fDocHandler->endElement(fElemQNameBuf.getRawBuffer()); } else { fDocHandler->startElement(elemDecl.getBaseName(), fAttrList); // If its empty, send the end tag event now if (isEmpty) fDocHandler->endElement(elemDecl.getBaseName()); } } else { fDocHandler->startElement(elemDecl.getFullName(), fAttrList); // If its empty, send the end tag event now if (isEmpty) fDocHandler->endElement(elemDecl.getFullName()); } } // // If there are any installed advanced handlers, then lets call them // with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) { fAdvDHList[index]->startElement ( elemDecl , elemURLId , elemPrefix , attrList , attrCount , isEmpty , isRoot ); }}void SAXParser::startEntityReference(const XMLEntityDecl& entityDecl){ // // SAX has no way to report this. But, If there are any installed // advanced handlers, then lets call them with this info. // for (unsigned int index = 0; index < fAdvDHCount; index++) fAdvDHList[index]->startEntityReference(entityDecl);}// ---------------------------------------------------------------------------// SAXParser: Overrides of the DocTypeHandler interface// ---------------------------------------------------------------------------void SAXParser::attDef( const DTDElementDecl& , const DTDAttDef& , const bool){ // Unused by SAX DTDHandler interface at this time}void SAXParser::doctypeComment(const XMLCh* const){ // Unused by SAX DTDHandler interface at this time}void SAXParser::doctypeDecl(const DTDElementDecl& , const XMLCh* const , const XMLCh* const , const bool , const bool){ // Unused by SAX DTDHandler interface at this time}void SAXParser::doctypePI( const XMLCh* const , const XMLCh* const){ // Unused by SAX DTDHandler interface at this time}void SAXParser::doctypeWhitespace( const XMLCh* const , const unsigned int){ // Unused by SAX DTDHandler interface at this time}void SAXParser::elementDecl(const DTDElementDecl&, const bool){ // Unused by SAX DTDHandler interface at this time}void SAXParser::endAttList(const DTDElementDecl&){ // Unused by SAX DTDHandler interface at this time}void SAXParser::endIntSubset(){ // Unused by SAX DTDHandler interface at this time}void SAXParser::endExtSubset(){ // Unused by SAX DTDHandler interface at this time}void SAXParser::entityDecl( const DTDEntityDecl& entityDecl , const bool , const bool isIgnored){ // // If we have a DTD handler, and this entity is not ignored, and // its an unparsed entity, then send this one. // if (fDTDHandler && !isIgnored) { if (entityDecl.isUnparsed()) { fDTDHandler->unparsedEntityDecl ( entityDecl.getName() , entityDecl.getPublicId() , entityDecl.getSystemId() , entityDecl.getNotationName() ); } }}void SAXParser::resetDocType(){ // Just map to the DTD handler if (fDTDHandler) fDTDHandler->resetDocType();}void SAXParser::notationDecl( const XMLNotationDecl& notDecl , const bool isIgnored){ if (fDTDHandler && !isIgnored) { fDTDHandler->notationDecl ( notDecl.getName() , notDecl.getPublicId() , notDecl.getSystemId() ); }}void SAXParser::startAttList(const DTDElementDecl&){ // Unused by SAX DTDHandler interface at this time}void SAXParser::startIntSubset(){ // Unused by SAX DTDHandler interface at this time}void SAXParser::startExtSubset(){ // Unused by SAX DTDHandler interface at this time}void SAXParser::TextDecl( const XMLCh* const , const XMLCh* const){ // Unused by SAX DTDHandler interface at this time}// ---------------------------------------------------------------------------// SAXParser: Overrides of the XMLErrorReporter interface// ---------------------------------------------------------------------------void SAXParser::resetErrors(){ if (fErrorHandler) fErrorHandler->resetErrors();}void SAXParser::error( const unsigned int , const XMLCh* const , const XMLErrorReporter::ErrTypes errType , const XMLCh* const errorText , const XMLCh* const systemId , const XMLCh* const publicId , const XMLSSize_t lineNum , const XMLSSize_t colNum){ SAXParseException toThrow = SAXParseException ( errorText , publicId , systemId , lineNum , colNum , fMemoryManager ); if (!fErrorHandler) { if (errType == XMLErrorReporter::ErrType_Fatal) throw toThrow; else return; } if (errType == XMLErrorReporter::ErrType_Warning) fErrorHandler->warning(toThrow); else if (errType == XMLErrorReporter::ErrType_Fatal) fErrorHandler->fatalError(toThrow); else fErrorHandler->error(toThrow);}// ---------------------------------------------------------------------------// SAXParser: Handlers for the XMLEntityHandler interface// ---------------------------------------------------------------------------void SAXParser::endInputSource(const InputSource&){}bool SAXParser::expandSystemId(const XMLCh* const, XMLBuffer&){ return false;}void SAXParser::resetEntities(){ // Nothing to do for this one}InputSource*SAXParser::resolveEntity( const XMLCh* const publicId , const XMLCh* const systemId , const XMLCh* const){ // Just map to the SAX entity resolver handler if (fEntityResolver) return fEntityResolver->resolveEntity(publicId, systemId); return 0;}InputSource*SAXParser::resolveEntity( XMLResourceIdentifier* resourceIdentifier ){ // Just map to the SAX entity resolver handler if (fEntityResolver) return fEntityResolver->resolveEntity(resourceIdentifier->getPublicId(), resourceIdentifier->getSystemId()); if (fXMLEntityResolver) return fXMLEntityResolver->resolveEntity(resourceIdentifier); return 0;}void SAXParser::startInputSource(const InputSource&){ // Nothing to do for this one}// ---------------------------------------------------------------------------// SAXParser: Deprecated methods// ---------------------------------------------------------------------------bool SAXParser::getDoValidation() const{ // // We don't want to tie the public parser classes to the enum used // by the scanner, so we use a separate one and map. // // DON'T mix the new and old methods!! // const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); if (scheme == XMLScanner::Val_Always) return true; return false;}void SAXParser::setDoValidation(const bool newState){ fScanner->setDoValidation ( newState ? XMLScanner::Val_Always : XMLScanner::Val_Never );}// ---------------------------------------------------------------------------// SAXParser: Grammar preparsing methods// ---------------------------------------------------------------------------Grammar* SAXParser::loadGrammar(const char* const systemId, const short grammarType, const bool toCache){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); Grammar* grammar = 0; try { fParseInProgress = true; grammar = fScanner->loadGrammar(systemId, grammarType, toCache); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch(...) { fParseInProgress = false; throw; } return grammar;}Grammar* SAXParser::loadGrammar(const XMLCh* const systemId, const short grammarType, const bool toCache){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); Grammar* grammar = 0; try { fParseInProgress = true; grammar = fScanner->loadGrammar(systemId, grammarType, toCache); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch(...) { fParseInProgress = false; throw; } return grammar;}Grammar* SAXParser::loadGrammar(const InputSource& source, const short grammarType, const bool toCache){ // Avoid multiple entrance if (fParseInProgress) ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager); Grammar* grammar = 0; try { fParseInProgress = true; grammar = fScanner->loadGrammar(source, grammarType, toCache); fParseInProgress = false; } catch(const OutOfMemoryException&) { throw; } catch(...) { fParseInProgress = false; throw; } return grammar;}void SAXParser::resetCachedGrammarPool(){ fGrammarResolver->resetCachedGrammar();}XERCES_CPP_NAMESPACE_END
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?