abstractdomparser.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,615 行 · 第 1/4 页

CPP
1,615
字号
                    fInternalSubset.append(chOpenParen );                    for(int i=0; i<length; i++) {                        if (enumString[i] == chSpace)                            fInternalSubset.append(chPipe);                        else                            fInternalSubset.append(enumString[i]);                    }                    fInternalSubset.append(chCloseParen);                }                break;            }            //get te default types of the attlist            const XMLAttDef::DefAttTypes def = attDef.getDefaultType();            switch(def)            {            case XMLAttDef::Required :                fInternalSubset.append(chSpace);                fInternalSubset.append(XMLUni::fgRequiredString);                break;            case XMLAttDef::Implied :                fInternalSubset.append(chSpace);                fInternalSubset.append(XMLUni::fgImpliedString);                break;            case XMLAttDef::Fixed :                fInternalSubset.append(chSpace);                fInternalSubset.append(XMLUni::fgFixedString);                break;            }            const XMLCh* defaultValue = attDef.getValue();            if (defaultValue != 0) {                fInternalSubset.append(chSpace);                fInternalSubset.append(chDoubleQuote);                fInternalSubset.append(defaultValue);                fInternalSubset.append(chDoubleQuote);            }        }    }}void AbstractDOMParser::doctypeComment(    const   XMLCh* const    comment){    if (fDocumentType->isIntSubsetReading())    {        if (comment != 0)        {            fInternalSubset.append(XMLUni::fgCommentString);            fInternalSubset.append(chSpace);            fInternalSubset.append(comment);            fInternalSubset.append(chSpace);            fInternalSubset.append(chDash);            fInternalSubset.append(chDash);            fInternalSubset.append(chCloseAngle);        }    }}void AbstractDOMParser::doctypeDecl(    const   DTDElementDecl& elemDecl    , const XMLCh* const    publicId    , const XMLCh* const    systemId    , const bool    , const bool){    fDocumentType = (DOMDocumentTypeImpl *) fDocument->createDocumentType(elemDecl.getFullName(), publicId, systemId);    fDocument->setDocumentType(fDocumentType);}void AbstractDOMParser::doctypePI(    const   XMLCh* const    target    , const XMLCh* const    data){    if (fDocumentType->isIntSubsetReading())    {        //add these chars to internalSubset variable        fInternalSubset.append(chOpenAngle);        fInternalSubset.append(chQuestion);        fInternalSubset.append(target);        fInternalSubset.append(chSpace);        fInternalSubset.append(data);        fInternalSubset.append(chQuestion);        fInternalSubset.append(chCloseAngle);    }	}void AbstractDOMParser::doctypeWhitespace(    const   XMLCh* const    chars    , const unsigned int){    if (fDocumentType->isIntSubsetReading())        fInternalSubset.append(chars);}void AbstractDOMParser::elementDecl(    const   DTDElementDecl& decl    , const bool){    if (fDocumentType->isIntSubsetReading())    {        fInternalSubset.append(chOpenAngle);        fInternalSubset.append(chBang);        fInternalSubset.append(XMLUni::fgElemString);        fInternalSubset.append(chSpace);        fInternalSubset.append(decl.getFullName());        //get the ContentSpec information        const XMLCh* contentModel = decl.getFormattedContentModel();        if (contentModel != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(contentModel);        }        fInternalSubset.append(chCloseAngle);    }}void AbstractDOMParser::endAttList(    const   DTDElementDecl& elemDecl){    if (fDocumentType->isIntSubsetReading())    {        //print the closing angle        fInternalSubset.append(chCloseAngle);    }	// this section sets up default attributes.	// default attribute nodes are stored in a NamedNodeMap DocumentTypeImpl::elements	// default attribute data attached to the document is used to conform to the	// DOM spec regarding creating element nodes & removing attributes with default values	// see DocumentTypeImpl	if (elemDecl.hasAttDefs())	{		        XMLAttDefList* defAttrs = &elemDecl.getAttDefList();        XMLAttDef* attr = 0;        DOMAttrImpl * insertAttr = 0;        DOMElement     *elem  = fDocument->createElement(elemDecl.getFullName());        DOMElementImpl *elemImpl = (DOMElementImpl *) elem;        for(unsigned int i=0; i<defAttrs->getAttDefCount(); i++)        {            attr = &defAttrs->getAttDef(i);            if (attr->getValue() != 0)            {                if (fScanner->getDoNamespaces())                {                    // DOM Level 2 wants all namespace declaration attributes                    // to be bound to "http://www.w3.org/2000/xmlns/"                    // So as long as the XML parser doesn't do it, it needs to                    // done here.                    const XMLCh* qualifiedName = attr->getFullName();                    int index = DOMDocumentImpl::indexofQualifiedName(qualifiedName);                    XMLBufBid bbQName(&fBufMgr);                    XMLBuffer& buf = bbQName.getBuffer();                    static const XMLCh XMLNS[] = {                        chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};                    if (index > 0) {                        // there is prefix                        // map to XML URI for all cases except when prefix == "xmlns"                        XMLCh* prefix;                        XMLCh temp[1000];                        if (index > 999)                            prefix = (XMLCh*) fMemoryManager->allocate                            (                                (index + 1) * sizeof(XMLCh)                            );//new XMLCh[index+1];                        else                            prefix = temp;                        XMLString::subString(prefix ,qualifiedName, 0, index, fMemoryManager);                        if (XMLString::equals(prefix,XMLNS))                            buf.append(XMLUni::fgXMLNSURIName);                        else                            buf.append(XMLUni::fgXMLURIName);                        if (index > 999)                            fMemoryManager->deallocate(prefix);//delete [] prefix;                    }                    else {                        //   No prefix                        if (XMLString::equals(qualifiedName,XMLNS))                            buf.append(XMLUni::fgXMLNSURIName);                    }                    insertAttr = (DOMAttrImpl *) fDocument->createAttributeNS(                       buf.getRawBuffer(),     // NameSpaceURI                       qualifiedName);   // qualified name                    DOMNode* remAttr = elemImpl->setAttributeNodeNS(insertAttr);                    if (remAttr)                        remAttr->release();                }                else                {                    // Namespaces is turned off...                    insertAttr = (DOMAttrImpl *) fDocument->createAttribute(attr->getFullName());                    DOMNode* remAttr = elemImpl->setAttributeNode(insertAttr);                    if (remAttr)                        remAttr->release();                }                insertAttr->setValue(attr->getValue());                insertAttr->setSpecified(false);            }        }        DOMNode* rem = fDocumentType->getElements()->setNamedItem(elemImpl);        if (rem)            rem->release();    }}void AbstractDOMParser::endIntSubset(){    fDocumentType->setInternalSubset(fInternalSubset.getRawBuffer());    // the buffer shouldn't be released as it is reused in the next parse    // fBufMgr.releaseBuffer(fInternalSubset);    fDocumentType->fIntSubsetReading = false;}void AbstractDOMParser::endExtSubset(){}void AbstractDOMParser::entityDecl(    const   DTDEntityDecl&  entityDecl    , const bool    , const bool){    DOMEntityImpl* entity = (DOMEntityImpl *) fDocument->createEntity(entityDecl.getName());    entity->setPublicId(entityDecl.getPublicId());    entity->setSystemId(entityDecl.getSystemId());    entity->setNotationName(entityDecl.getNotationName());    entity->setBaseURI(entityDecl.getBaseURI());    DOMEntityImpl *previousDef = (DOMEntityImpl *)	    fDocumentType->getEntities()->setNamedItem( entity );    if (previousDef)        previousDef->release();    if (fDocumentType->isIntSubsetReading())    {        //add thes chars to internalSubset variable        fInternalSubset.append(chOpenAngle);        fInternalSubset.append(chBang);        fInternalSubset.append(XMLUni::fgEntityString);        fInternalSubset.append(chSpace);        fInternalSubset.append(entityDecl.getName());        const XMLCh* id = entity->getPublicId();        if (id != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(XMLUni::fgPubIDString);            fInternalSubset.append(chSpace);            fInternalSubset.append(chDoubleQuote);            fInternalSubset.append(id);            fInternalSubset.append(chDoubleQuote);        }        id = entity->getSystemId();        if (id != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(XMLUni::fgSysIDString);            fInternalSubset.append(chSpace);            fInternalSubset.append(chDoubleQuote);            fInternalSubset.append(id);            fInternalSubset.append(chDoubleQuote);        }        id = entity->getNotationName();        if (id != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(XMLUni::fgNDATAString);            fInternalSubset.append(chSpace);            fInternalSubset.append(id);        }        id = entityDecl.getValue();        if (id !=0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(chDoubleQuote);            fInternalSubset.append(id);            fInternalSubset.append(chDoubleQuote);        }        fInternalSubset.append(chCloseAngle);    }}void AbstractDOMParser::resetDocType(){	fDocumentType = 0;}void AbstractDOMParser::notationDecl(    const   XMLNotationDecl&    notDecl    , const bool){    DOMNotationImpl* notation = (DOMNotationImpl *)fDocument->createNotation(notDecl.getName());    notation->setPublicId(notDecl.getPublicId());    notation->setSystemId(notDecl.getSystemId());    notation->setBaseURI(notDecl.getBaseURI());    DOMNode* rem = fDocumentType->getNotations()->setNamedItem( notation );    if (rem)        rem->release();    if (fDocumentType->isIntSubsetReading())    {        //add thes chars to internalSubset variable        fInternalSubset.append(chOpenAngle);        fInternalSubset.append(chBang);        fInternalSubset.append(XMLUni::fgNotationString);        fInternalSubset.append(chSpace);        fInternalSubset.append(notDecl.getName());        const XMLCh* id = notation->getPublicId();        if (id != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(XMLUni::fgPubIDString);            fInternalSubset.append(chSpace);            fInternalSubset.append(chDoubleQuote);            fInternalSubset.append(id);            fInternalSubset.append(chDoubleQuote);        }        id = notation->getSystemId();        if (id != 0) {            fInternalSubset.append(chSpace);            fInternalSubset.append(XMLUni::fgSysIDString);            fInternalSubset.append(chSpace);            fInternalSubset.append(chDoubleQuote);            fInternalSubset.append(id);            fInternalSubset.append(chDoubleQuote);        }        fInternalSubset.append(chCloseAngle);    }}void AbstractDOMParser::startAttList(    const   DTDElementDecl& elemDecl){    if (fDocumentType->isIntSubsetReading())    {        fInternalSubset.append(chOpenAngle);        fInternalSubset.append(chBang);        fInternalSubset.append(XMLUni::fgAttListString);        fInternalSubset.append(chSpace);        fInternalSubset.append(elemDecl.getFullName());    }}void AbstractDOMParser::startIntSubset(){	fDocumentType->fIntSubsetReading = true;}void AbstractDOMParser::startExtSubset(){}void AbstractDOMParser::TextDecl(    const   XMLCh* const    versionStr    , const XMLCh* const    encodingStr){    if (fCurrentEntity) {        fCurrentEntity->setVersion(versionStr);        fCurrentEntity->setEncoding(encodingStr);    }}XERCES_CPP_NAMESPACE_END

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?