simplecontentmodel.cpp

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

CPP
523
字号
            break;        case ContentSpecNode::Sequence :            //            //  There must be two children and they must be the two values            //  we stored, in the stored order. So first check the obvious            //  problem of an empty content, which would never be valid            //  in this content mode.            //            if (!childCount)                return 0;            if (childCount == 2) {                if (fDTD) {                    if (!XMLString::equals(children[0]->getRawName(), fFirstChild->getRawName())) {                        return 0;                    }                    if (!XMLString::equals(children[1]->getRawName(), fSecondChild->getRawName())) {                        return 1;                    }                }                else {                    if ((children[0]->getURI() != fFirstChild->getURI()) ||                        !XMLString::equals(children[0]->getLocalPart(), fFirstChild->getLocalPart())) {                        return 0;                    }                    if ((children[1]->getURI() != fSecondChild->getURI()) ||                        !XMLString::equals(children[1]->getLocalPart(), fSecondChild->getLocalPart())) {                        return 1;                    }                }            }            else {                if (childCount > 2) {                    return 2;                }                return childCount;            }            break;        default :            ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager);            break;    }    return -1;}int SimpleContentModel::validateContentSpecial(QName** const          children                                            , const unsigned int      childCount                                            , const unsigned int                                            , GrammarResolver*  const pGrammarResolver                                            , XMLStringPool*    const pStringPool) const{    SubstitutionGroupComparator comparator(pGrammarResolver, pStringPool);    //    //  According to the type of operation, we do the correct type of    //  content check.    //    unsigned int index;    switch(fOp & 0x0f)    {        case ContentSpecNode::Leaf :            //            //  There can only be one child and it has to be of the            //  element type we stored.            //            if (!childCount)                return 0;            if ((children[0]->getURI() != fFirstChild->getURI()) ||                !XMLString::equals(children[0]->getLocalPart(), fFirstChild->getLocalPart()))            {                if (!comparator.isEquivalentTo(children[0], fFirstChild))                   return 0;            }            if (childCount > 1)                return 1;            break;        case ContentSpecNode::ZeroOrOne :            //            //  If the child count is greater than one, then obviously            //  bad. Otherwise, if its one, then the one child must be            //  of the type we stored.            //            if ((childCount == 1) &&               ((children[0]->getURI() != fFirstChild->getURI()) ||                !XMLString::equals(children[0]->getLocalPart(), fFirstChild->getLocalPart())))            {                if(!comparator.isEquivalentTo(children[0], fFirstChild))                    return 0;            }            if (childCount > 1)                return 1;            break;        case ContentSpecNode::ZeroOrMore :            //            //  If the child count is zero, that's fine. If its more than            //  zero, then make sure that all children are of the element            //  type that we stored.            //            if (childCount > 0)            {                for (index = 0; index < childCount; index++)                {                    if ((children[index]->getURI() != fFirstChild->getURI()) ||                        !XMLString::equals(children[index]->getLocalPart(), fFirstChild->getLocalPart()))                    {    				    if (!comparator.isEquivalentTo(children[index], fFirstChild))                            return index;                    }                }            }            break;        case ContentSpecNode::OneOrMore :            //            //  If the child count is zero, that's an error. If its more            //  than zero, then make sure that all children are of the            //  element type that we stored.            //            if (childCount == 0)                return 0;            for (index = 0; index < childCount; index++)            {                if ((children[index]->getURI() != fFirstChild->getURI()) ||                    !XMLString::equals(children[index]->getLocalPart(), fFirstChild->getLocalPart()))                {    			    if (!comparator.isEquivalentTo(children[index], fFirstChild))                        return index;                }            }            break;        case ContentSpecNode::Choice :            //            //  There can only be one child, and it must be one of the            //  two types we stored.            //            if (!childCount)                return 0;            if (((children[0]->getURI() != fFirstChild->getURI()) ||                 !XMLString::equals(children[0]->getLocalPart(), fFirstChild->getLocalPart())) &&                ((children[0]->getURI() != fSecondChild->getURI()) ||                 !XMLString::equals(children[0]->getLocalPart(), fSecondChild->getLocalPart())))            {                 if (!comparator.isEquivalentTo(children[0], fFirstChild) &&                     !comparator.isEquivalentTo(children[0], fSecondChild) )                     return 0;            }            if (childCount > 1)                return 1;            break;        case ContentSpecNode::Sequence :            //            //  There must be two children and they must be the two values            //  we stored, in the stored order. So first check the obvious            //  problem of an empty content, which would never be valid            //  in this content mode.            //            if (!childCount)                return 0;            if (childCount == 2)            {                if ((children[0]->getURI() != fFirstChild->getURI()) ||                    !XMLString::equals(children[0]->getLocalPart(), fFirstChild->getLocalPart()))                {                    if(!comparator.isEquivalentTo(children[0], fFirstChild))                        return 0;                }                if ((children[1]->getURI() != fSecondChild->getURI()) ||                    !XMLString::equals(children[1]->getLocalPart(), fSecondChild->getLocalPart()))                {                    if (!comparator.isEquivalentTo(children[1], fSecondChild))                        return 1;                }            }            else            {                if (childCount > 2)                {                    return 2;                }                return childCount;            }            break;        default :            ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_UnknownCMSpecType, fMemoryManager);            break;    }    return -1;}ContentLeafNameTypeVector* SimpleContentModel::getContentLeafNameTypeVector() const{    return 0;}void SimpleContentModel::checkUniqueParticleAttribution    (        SchemaGrammar*    const pGrammar      , GrammarResolver*  const pGrammarResolver      , XMLStringPool*    const pStringPool      , XMLValidator*     const pValidator      , unsigned int*     const pContentSpecOrgURI      , const XMLCh*            pComplexTypeName /*= 0*/    ){    // rename back    unsigned int orgURIIndex = 0;    orgURIIndex = fFirstChild->getURI();    if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&        (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&        (orgURIIndex != XMLElementDecl::fgPCDataElemId))        fFirstChild->setURI(pContentSpecOrgURI[orgURIIndex]);    orgURIIndex = fSecondChild->getURI();    if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&        (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&        (orgURIIndex != XMLElementDecl::fgPCDataElemId))        fSecondChild->setURI(pContentSpecOrgURI[orgURIIndex]);    // only possible violation is when it's a choice    if ((fOp & 0x0f) == ContentSpecNode::Choice) {        SubstitutionGroupComparator comparator(pGrammarResolver, pStringPool);        if (XercesElementWildcard::conflict(pGrammar,                                            ContentSpecNode::Leaf,                                            fFirstChild,                                            ContentSpecNode::Leaf,                                            fSecondChild,                                            &comparator))            pValidator->emitError(XMLValid::UniqueParticleAttributionFail,                                  pComplexTypeName,                                  fFirstChild->getRawName(),                                  fSecondChild->getRawName());    }}XERCES_CPP_NAMESPACE_END

⌨️ 快捷键说明

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