mixedcontentmodel.cpp

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

CPP
486
字号
        unsigned int inIndex = 0;        for (unsigned int outIndex = 0; outIndex < childCount; outIndex++) {            // Get the current child out of the source index            const QName* curChild = children[outIndex];            // If its PCDATA, then we just accept that            if (curChild->getURI() == XMLElementDecl::fgPCDataElemId)                continue;            ContentSpecNode::NodeTypes type = fChildTypes[inIndex];            const QName* inChild = fChildren[inIndex];            if (type == ContentSpecNode::Leaf) {                if (fDTD) {                    if (!XMLString::equals(inChild->getRawName(), curChild->getRawName())) {                        return outIndex;                    }                }                else {                    if ((inChild->getURI() != curChild->getURI()) ||                        (!XMLString::equals(inChild->getLocalPart(), curChild->getLocalPart()))) {                        return outIndex;                    }                }            }            else if (type == ContentSpecNode::Any) {            }            else if (type == ContentSpecNode::Any_NS) {                if (inChild->getURI() != curChild->getURI())                    return outIndex;            }            else if (type == ContentSpecNode::Any_Other) {                if (inChild->getURI() == curChild->getURI())                    return outIndex;            }            // advance index            inIndex++;        }    }    // can appear in any order    else {        for (unsigned int outIndex = 0; outIndex < childCount; outIndex++) {            // Get the current child out of the source index            const QName* curChild = children[outIndex];            // If its PCDATA, then we just accept that            if (curChild->getURI() == XMLElementDecl::fgPCDataElemId)                continue;            // And try to find it in our list            unsigned int inIndex = 0;            for (; inIndex < fCount; inIndex++)            {                ContentSpecNode::NodeTypes type = fChildTypes[inIndex];                const QName* inChild = fChildren[inIndex];                if (type == ContentSpecNode::Leaf) {                    if (fDTD) {                        if (XMLString::equals(inChild->getRawName(), curChild->getRawName())) {                            break;                        }                    }                    else {                        if ((inChild->getURI() == curChild->getURI()) &&                            (XMLString::equals(inChild->getLocalPart(), curChild->getLocalPart()))) {                            break;                        }                    }                }                else if (type == ContentSpecNode::Any) {                    break;                }                else if (type == ContentSpecNode::Any_NS) {                    if (inChild->getURI() == curChild->getURI())                        break;                }                else if (type == ContentSpecNode::Any_Other) {                    if (inChild->getURI() != curChild->getURI())                        break;                }                // REVISIT: What about checking for multiple ANY matches?                //          The content model ambiguity *could* be checked                //          by the caller before constructing the mixed                //          content model.            }            // We did not find this one, so the validation failed            if (inIndex == fCount)                return outIndex;        }    }    // Everything seems to be in order, so return success    // success    return -1;}int MixedContentModel::validateContentSpecial(QName** const           children                                            , const unsigned int      childCount                                            , const unsigned int                                            , GrammarResolver*  const pGrammarResolver                                            , XMLStringPool*    const pStringPool) const{    SubstitutionGroupComparator comparator(pGrammarResolver, pStringPool);    // must match order    if (fOrdered) {        unsigned int inIndex = 0;        for (unsigned int outIndex = 0; outIndex < childCount; outIndex++) {            // Get the current child out of the source index            QName* curChild = children[outIndex];            // If its PCDATA, then we just accept that            if (curChild->getURI() == XMLElementDecl::fgPCDataElemId)                continue;            ContentSpecNode::NodeTypes type = fChildTypes[inIndex];            QName* inChild = fChildren[inIndex];            if (type == ContentSpecNode::Leaf) {                if ( !comparator.isEquivalentTo(curChild, inChild))                    return outIndex;            }            else if (type == ContentSpecNode::Any) {            }            else if (type == ContentSpecNode::Any_NS) {                if (inChild->getURI() != curChild->getURI())                    return outIndex;            }            else if (type == ContentSpecNode::Any_Other) {                if (inChild->getURI() == curChild->getURI())                    return outIndex;            }            // advance index            inIndex++;        }    }    // can appear in any order    else {        for (unsigned int outIndex = 0; outIndex < childCount; outIndex++) {            // Get the current child out of the source index            QName* curChild = children[outIndex];            // If its PCDATA, then we just accept that            if (curChild->getURI() == XMLElementDecl::fgPCDataElemId)                continue;            // And try to find it in our list            unsigned int inIndex = 0;            for (; inIndex < fCount; inIndex++)            {                ContentSpecNode::NodeTypes type = fChildTypes[inIndex];                QName* inChild = fChildren[inIndex];                if (type == ContentSpecNode::Leaf) {                    if ( comparator.isEquivalentTo(curChild, inChild))                        break;                }                else if (type == ContentSpecNode::Any) {                    break;                }                else if (type == ContentSpecNode::Any_NS) {                    if (inChild->getURI() == curChild->getURI())                        break;                }                else if (type == ContentSpecNode::Any_Other) {                    if (inChild->getURI() != curChild->getURI())                        break;                }                // REVISIT: What about checking for multiple ANY matches?                //          The content model ambiguity *could* be checked                //          by the caller before constructing the mixed                //          content model.            }            // We did not find this one, so the validation failed            if (inIndex == fCount)                return outIndex;        }    }    // Everything seems to be in order, so return success    // success    return -1;}// ---------------------------------------------------------------------------//  MixedContentModel: Private helper methods// ---------------------------------------------------------------------------voidMixedContentModel::buildChildList(  ContentSpecNode* const       curNode                                  , ValueVectorOf<QName*>&       toFill                                  , ValueVectorOf<ContentSpecNode::NodeTypes>& toType){    // Get the type of spec node our current node is    const ContentSpecNode::NodeTypes curType = curNode->getType();    // If its a leaf, then store its id in the target list    if ((curType == ContentSpecNode::Leaf)      ||        (curType == ContentSpecNode::Any)       ||        (curType == ContentSpecNode::Any_Other) ||        (curType == ContentSpecNode::Any_NS)   )    {        toFill.addElement(curNode->getElement());        toType.addElement(curType);        return;    }    // Get both the child node pointers    ContentSpecNode* leftNode = curNode->getFirst();    ContentSpecNode* rightNode = curNode->getSecond();    // And recurse according to the type of node    if (((curType & 0x0f) == ContentSpecNode::Choice)    ||  ((curType & 0x0f) == ContentSpecNode::Sequence))    {        // Recurse on the left and right nodes        buildChildList(leftNode, toFill, toType);        // The last node of a choice or sequence has a null right        if (rightNode)            buildChildList(rightNode, toFill, toType);    }    else if ((curType == ContentSpecNode::OneOrMore)         ||  (curType == ContentSpecNode::ZeroOrOne)         ||  (curType == ContentSpecNode::ZeroOrMore))    {        // Just do the left node on this one        buildChildList(leftNode, toFill, toType);    }}XERCES_CPP_NAMESPACE_END

⌨️ 快捷键说明

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