sax2xmlreaderimpl.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,817 行 · 第 1/4 页
CPP
1,817 行
{ XMLBuffer * buf = fPrefixes->pop() ; fStringBuffers.releaseBuffer(*buf) ; } }}void SAX2XMLReaderImpl::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 SAX2XMLReaderImpl::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) { XMLBufBid elemQName( &fStringBuffers ) ; if (elemPrefix && *elemPrefix) { elemQName.set(elemPrefix); elemQName.append(chColon); } elemQName.append(elemDecl.getBaseName()); if (getDoNamespaces()) { unsigned int numPrefix = 0; const XMLCh* nsString = XMLUni::fgXMLNSString; const XMLCh* nsPrefix = 0; const XMLCh* nsURI = 0; const XMLAttr* tempAttr = 0; if (!fNamespacePrefix) { fTempAttrVec->removeAllElements(); } for (unsigned int i = 0; i < attrCount; i++) { tempAttr = attrList.elementAt(i); if (XMLString::equals(tempAttr->getQName(), nsString)) nsURI = tempAttr->getValue(); if (XMLString::equals(tempAttr->getPrefix(), nsString)) { nsPrefix = tempAttr->getName(); nsURI = tempAttr->getValue(); } if (!fNamespacePrefix) { if (nsURI == 0) fTempAttrVec->addElement((XMLAttr* const)tempAttr); } if (nsURI != 0) { if (nsPrefix == 0) nsPrefix = XMLUni::fgZeroLenString; fDocHandler->startPrefixMapping(nsPrefix, nsURI); XMLBuffer &buf = fStringBuffers.bidOnBuffer(); buf.set ( nsPrefix ) ; fPrefixes->push(&buf) ; numPrefix++; } nsURI = 0; nsPrefix = 0; } fPrefixCounts->push(numPrefix) ; if (!fNamespacePrefix) fAttrList.setVector(fTempAttrVec, fTempAttrVec->size(), fScanner); else fAttrList.setVector(&attrList, attrCount, fScanner); // call startElement() with namespace declarations fDocHandler->startElement ( fScanner->getURIText(elemURLId) , elemDecl.getBaseName() , elemQName.getRawBuffer() , fAttrList ); } else // no namespace { fAttrList.setVector(&attrList, attrCount, fScanner); fDocHandler->startElement(XMLUni::fgZeroLenString, elemDecl.getBaseName(), elemDecl.getFullName(), fAttrList); } // If its empty, send the end tag event now if (isEmpty) { // call endPrefixMapping appropriately. if (getDoNamespaces()) { fDocHandler->endElement ( fScanner->getURIText(elemURLId) , elemDecl.getBaseName() , elemQName.getRawBuffer() ); unsigned int numPrefix = fPrefixCounts->pop(); for (unsigned int i = 0; i < numPrefix; ++i) { XMLBuffer * buf = fPrefixes->pop() ; fDocHandler->endPrefixMapping( buf->getRawBuffer() ); fStringBuffers.releaseBuffer(*buf) ; } } else { fDocHandler->endElement(XMLUni::fgZeroLenString, elemDecl.getBaseName(), 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 SAX2XMLReaderImpl::endElement( const XMLElementDecl& elemDecl , const unsigned int uriId , const bool isRoot , const XMLCh* const elemPrefix){ // Just map to the SAX document handler if (fDocHandler) { // get the prefixes back so that we can call endPrefixMapping() if (getDoNamespaces()) { XMLBufBid elemQName( &fStringBuffers ) ; if (elemPrefix && *elemPrefix) { elemQName.set(elemPrefix); elemQName.append(chColon); } elemQName.append(elemDecl.getBaseName()); fDocHandler->endElement ( fScanner->getURIText(uriId) , elemDecl.getBaseName() , elemQName.getRawBuffer() ); unsigned int numPrefix = fPrefixCounts->pop(); for (unsigned int i = 0; i < numPrefix; i++) { XMLBuffer * buf = fPrefixes->pop() ; fDocHandler->endPrefixMapping( buf->getRawBuffer() ); fStringBuffers.releaseBuffer(*buf) ; } } else { fDocHandler->endElement(XMLUni::fgZeroLenString, elemDecl.getBaseName(), 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]->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 SAX2XMLReaderImpl::startEntityReference(const XMLEntityDecl& entityDecl){ // Call the installed LexicalHandler. if (fLexicalHandler) fLexicalHandler->startEntity(entityDecl.getName()); // // 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);}// ---------------------------------------------------------------------------// SAX2XMLReaderImpl: Overrides of the DocTypeHandler interface// ---------------------------------------------------------------------------void SAX2XMLReaderImpl::attDef( const DTDElementDecl& elemDecl , const DTDAttDef& attDef , const bool ignoring){ if (fDeclHandler && !ignoring) { XMLAttDef::AttTypes attType = attDef.getType(); XMLAttDef::DefAttTypes defAttType = attDef.getDefaultType(); const XMLCh* defAttTypeStr = XMLUni::fgNullString; bool isEnumeration = (attType == XMLAttDef::Notation || attType == XMLAttDef::Enumeration); XMLBuffer enumBuf(128, fMemoryManager); if (defAttType == XMLAttDef::Fixed || defAttType == XMLAttDef::Implied || defAttType == XMLAttDef::Required) { defAttTypeStr = attDef.getDefAttTypeString(defAttType, fMemoryManager); } if (isEnumeration) { const XMLCh* enumString = attDef.getEnumeration(); unsigned int enumLen = XMLString::stringLen(enumString); if (attType == XMLAttDef::Notation) { enumBuf.set(XMLUni::fgNotationString); enumBuf.append(chSpace); } enumBuf.append(chOpenParen); for (unsigned int i=0; i<enumLen; i++) { if (enumString[i] == chSpace) enumBuf.append(chPipe); else enumBuf.append(enumString[i]); } enumBuf.append(chCloseParen); } fDeclHandler->attributeDecl(elemDecl.getFullName(), attDef.getFullName(), (isEnumeration) ? enumBuf.getRawBuffer() : attDef.getAttTypeString(attDef.getType(), fMemoryManager), defAttTypeStr, attDef.getValue()); }}void SAX2XMLReaderImpl::doctypeComment(const XMLCh* const commentText){ if (fLexicalHandler) { // SAX2 reports comment text like characters -- as an // array with a length. fLexicalHandler->comment(commentText, XMLString::stringLen(commentText)); }}void SAX2XMLReaderImpl::doctypeDecl(const DTDElementDecl& elemDecl , const XMLCh* const publicId , const XMLCh* const systemId , const bool hasIntSubset , const bool hasExtSubset){ // Call the installed LexicalHandler. if (fLexicalHandler && (hasIntSubset || hasExtSubset)) fLexicalHandler->startDTD(elemDecl.getFullName(), publicId, systemId); fHasExternalSubset = hasExtSubset; // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::doctypePI( const XMLCh* const , const XMLCh* const){ // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::doctypeWhitespace( const XMLCh* const , const unsigned int){ // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::elementDecl(const DTDElementDecl& elemDecl, const bool isIgnored){ if (fDeclHandler && !isIgnored) fDeclHandler->elementDecl(elemDecl.getFullName(), elemDecl.getFormattedContentModel());}void SAX2XMLReaderImpl::endAttList(const DTDElementDecl&){ // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::endIntSubset(){ // Call the installed LexicalHandler. if (!fHasExternalSubset && fLexicalHandler) fLexicalHandler->endDTD(); // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::endExtSubset(){ // Call the installed LexicalHandler. if (fLexicalHandler) { fLexicalHandler->endEntity(gDTDEntityStr); fLexicalHandler->endDTD(); } // Unused by SAX DTDHandler interface at this time}void SAX2XMLReaderImpl::entityDecl( const DTDEntityDecl& entityDecl , const bool isPEDecl , const bool isIgnored){ // // If we have a DTD handler, and this entity is not ignored, and // its an unparsed entity, then send this one, else if we have a Decl // handler then send this one. // if (!isIgnored) { if (entityDecl.isUnparsed()) { if (fDTDHandler) { fDTDHandler->unparsedEntityDecl ( entityDecl.getName() , entityDecl.getPublicId() , entityDecl.getSystemId() , entityDecl.getNotationName() ); } } else if (fDeclHandler) { const XMLCh* entityName = entityDecl.getName(); ArrayJanitor<XMLCh> tmpNameJan(0); if (isPEDecl) { unsigned int nameLen = XMLString::stringLen(entityName); XMLCh* tmpName = (XMLCh*) fMemoryManager->allocate ( (nameLen + 2) * sizeof(XMLCh) );//new XMLCh[nameLen + 2]; tmpNameJan.reset(tmpName, fMemoryManager); tmpName[0] = chPercent; XMLString::copyString(tmpName + 1, entityName); entityName = tmpName; } if (entityDecl.isExternal()) { fDeclHandler->externalEntityDecl ( entityName , entityDecl.getPublicId() , entityDecl.getSystemId() ); } else { fDeclHandler->internalEntityDecl ( entityName , entityDecl.getValue() ); } } }}void SAX2XMLReaderImpl::resetDocType(){ fHasExternalSubset = false; // Just map to the DTD handler if (fDTDHandler) fDTDHandler->resetDocType();}void SAX2XMLReaderImpl::notationDecl( const XMLNotationDecl& notDecl , const bool isIgnored){ if (fDTDHandler && !isIgnored) { fDTDHandler->notationDecl ( notDecl.getName() , notDecl.getPublicId() , notDecl.getSystemId() ); }}void SAX2XMLReaderImpl::startAttList(const DTDElementDecl&){ // Unused by SAX DTDHandler interface at this time
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?