igxmlscanner2.cpp

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

CPP
1,601
字号
                        (                          XMLErrs::AttrAlreadyUsedInSTag                        , curAttr->getName()                        , elemDecl->getFullName()                        );                    }                }            }            else            {                if (fAttrDupChkRegistry->containsKey((void*)suffPtr, uriId))                {                    emitError                        (                         XMLErrs::AttrAlreadyUsedInSTag                        , curAttr->getName()                        , elemDecl->getFullName()                        );                }            }          }                if (retCount >= curAttListSize)        {            curAttr = new (fMemoryManager) XMLAttr            (                uriId                , suffPtr                , prefPtr                , normBuf.getRawBuffer()                , attType                , true                , fMemoryManager            );            toFill.addElement(curAttr);        }        else        {            curAttr = toFill.elementAt(retCount);            curAttr->set            (                uriId                , suffPtr                , prefPtr                , normBuf.getRawBuffer()                , attType            );            curAttr->setSpecified(true);        }        if (toUseHashTable)        {            fAttrDupChkRegistry->put((void*)suffPtr, uriId, curAttr);        }        if(psviAttr)            psviAttr->setValue(curAttr->getValue());                    // Bump the count of attrs in the list        retCount++;    }    //  Now, if there are any attributes declared by this element, let's    //  go through them and make sure that any required ones are provided,    //  and fault in any fixed ones and defaulted ones that are not provided    //  literally.    if (hasDefs)    {        // Check after all specified attrs are scanned        // (1) report error for REQUIRED attrs that are missing (V_TAGc)        // (2) add default attrs if missing (FIXED and NOT_FIXED)        XMLAttDefList &attDefList = getAttDefList(fGrammarType == Grammar::SchemaGrammarType, currType, elemDecl);        for(unsigned int i=0; i<attDefList.getAttDefCount(); i++)        {            // Get the current att def, for convenience and its def type            const XMLAttDef *curDef = &attDefList.getAttDef(i);            const XMLAttDef::DefAttTypes defType = curDef->getDefaultType();            unsigned int *attCountPtr = fAttDefRegistry->get((void *)curDef);            if (!attCountPtr || *attCountPtr < fElemCount)            { // did not occur                // note that since there is no attribute information                // item present, there is no PSVI infoset to augment here *except*                // that the element is invalid                //the attribute is not provided                if (fValidate)                {                    // If we are validating and its required, then an error                    if ((defType == XMLAttDef::Required) ||                        (defType == XMLAttDef::Required_And_Fixed)  )                    {                        fValidator->emitError                        (                            XMLValid::RequiredAttrNotProvided                            , curDef->getFullName()                        );                        if(fGrammarType == Grammar::SchemaGrammarType)                         {                            fPSVIElemContext.fErrorOccurred = true;                        }                    }                    else if ((defType == XMLAttDef::Default) ||                            (defType == XMLAttDef::Fixed)  )                    {                        if (fStandalone && curDef->isExternal())                        {                            // XML 1.0 Section 2.9                            // Document is standalone, so attributes must not be defaulted.                            fValidator->emitError(XMLValid::NoDefAttForStandalone, curDef->getFullName(), elemDecl->getFullName());                                                                                    if(fGrammarType == Grammar::SchemaGrammarType)                            {                                fPSVIElemContext.fErrorOccurred = true;                            }                        }                    }                }                //  Fault in the value if needed, and bump the att count.                if ((defType == XMLAttDef::Default)                    ||  (defType == XMLAttDef::Fixed))                {                    // Let the validator pass judgement on the attribute value                    if (fValidate)                    {                        fValidator->validateAttrValue                        (                            curDef                            , curDef->getValue()                            , false                            , elemDecl                        );                    }                    XMLAttr* curAtt;                    if (retCount >= curAttListSize)                    {                        curAtt = new (fMemoryManager) XMLAttr(fMemoryManager);                        fValidator->faultInAttr(*curAtt, *curDef);                        fAttrList->addElement(curAtt);                    }                    else                    {                        curAtt = fAttrList->elementAt(retCount);                        fValidator->faultInAttr(*curAtt, *curDef);                    }                    if (fGrammarType == Grammar::DTDGrammarType)                    {                        //  Map the new attribute's prefix to a URI id and store                        //  that in the attribute object.                        curAtt->setURIId                        (                            resolvePrefix(curAtt->getPrefix(), ElemStack::Mode_Attribute)                        );                    }                    // Indicate it was not explicitly specified and bump count                    curAtt->setSpecified(false);                    retCount++;                    if(getPSVIHandler() && fGrammarType == Grammar::SchemaGrammarType)                    {                        QName *attName = ((SchemaAttDef *)curDef)->getAttName();                        PSVIAttribute *defAttrToFill = fPSVIAttrList->getPSVIAttributeToFill                        (                            attName->getLocalPart(), fURIStringPool->getValueForId( attName->getURI())                        );                        XSAttributeDeclaration *defAttrDecl = (XSAttributeDeclaration *)fModel->getXSObject((void *)curDef);                        DatatypeValidator * attrDataType = ((SchemaAttDef *)curDef)->getDatatypeValidator();                        XSSimpleTypeDefinition *defAttrType =                             (XSSimpleTypeDefinition*)fModel->getXSObject(attrDataType);                        // would have occurred during validation of default value                        if(((SchemaValidator *)fValidator)->getErrorOccurred())                        {                            defAttrToFill->reset(                                fRootElemName                                , PSVIItem::VALIDITY_INVALID                                , PSVIItem::VALIDATION_FULL                                , defAttrType                                , 0                                , curDef->getValue()                                , true                                 , defAttrDecl                                , 0                            );                        }                        else                        {                            XSSimpleTypeDefinition *defAttrMemberType = 0;                            if(defAttrType->getVariety() == XSSimpleTypeDefinition::VARIETY_UNION)                            {                                defAttrMemberType = (XSSimpleTypeDefinition *)fModel->getXSObject                                (                                    ((SchemaValidator*)fValidator)->getMostRecentAttrValidator()                                );                            }                            defAttrToFill->reset(                                fRootElemName                                , PSVIItem::VALIDITY_VALID                                , PSVIItem::VALIDATION_FULL                                , defAttrType                                , defAttrMemberType                                , curDef->getValue()                                , true                                , defAttrDecl                                , (defAttrMemberType)?((SchemaValidator *)fValidator)->getMostRecentAttrValidator():attrDataType                            );                        }                         defAttrToFill->setValue(curDef->getValue());                    }                }            }            else if(attCountPtr)            {                //attribute is provided                // (schema) report error for PROHIBITED attrs that are present (V_TAGc)                if (defType == XMLAttDef::Prohibited && fValidate)                 {                    fValidator->emitError                    (                        XMLValid::ProhibitedAttributePresent                        , curDef->getFullName()                    );                    if(fGrammarType == Grammar::SchemaGrammarType)                     {                        fPSVIElemContext.fErrorOccurred = true;                        if (getPSVIHandler())                        {                            QName *attQName = ((SchemaAttDef *)curDef)->getAttName();                            // bad luck...                            PSVIAttribute *prohibitedAttr = fPSVIAttrList->getAttributePSVIByName                            (                                attQName->getLocalPart(),                                 fURIStringPool->getValueForId(attQName->getURI())                            );                            prohibitedAttr->updateValidity(PSVIItem::VALIDITY_INVALID);                        }                    }                }            }        }    }    return retCount;}//  This method will take a raw attribute value and normalize it according to//  the rules of the attribute type. It will put the resulting value into the//  passed buffer.////  This code assumes that escaped characters in the original value (via char//  refs) are prefixed by a 0xFFFF character. This is because some characters//  are legal if escaped only. And some escape chars are not subject to//  normalization rules.bool IGXMLScanner::normalizeAttValue( const   XMLAttDef* const    attDef                                      , const XMLCh* const        attName                                      , const XMLCh* const        value                                      ,       XMLBuffer&          toFill){    // A simple state value for a whitespace processing state machine    enum States    {        InWhitespace        , InContent    };    // Get the type and name    const XMLAttDef::AttTypes type = (attDef)                    ?attDef->getType()                    :XMLAttDef::CData;    // Assume its going to go fine, and empty the target buffer in preperation    bool retVal = true;    toFill.reset();    // Get attribute def - to check to see if it's declared externally or not    bool  isAttExternal = (attDef)                ?attDef->isExternal()                :false;    //  Loop through the chars of the source value and normalize it according    //  to the type.    States curState = InContent;    bool escaped;    bool firstNonWS = false;    XMLCh nextCh;    const XMLCh* srcPtr = value;    while (*srcPtr)    {        //  Get the next character from the source. We have to watch for        //  escaped characters (which are indicated by a 0xFFFF value followed        //  by the char that was escaped.)        nextCh = *srcPtr;        escaped = (nextCh == 0xFFFF);        if (escaped)            nextCh = *++srcPtr;        //  If its not escaped, then make sure its not a < character, which is        //  not allowed in attribute values.        if (!escaped && (*srcPtr == chOpenAngle))        {            emitError(XMLErrs::BracketInAttrValue, attName);            retVal = false;        }        if (type == XMLAttDef::CData || type > XMLAttDef::Notation)        {            if (!escaped)            {                if ((nextCh == 0x09) || (nextCh == 0x0A) || (nextCh == 0x0D))                {                    // Check Validity Constraint for Standalone document declaration                    // XML 1.0, Section 2.9                    if (fStandalone && fValidate && isAttExternal)                    {                         // Can't have a standalone document declaration of "yes" if  attribute                         // values are subject to normalisation

⌨️ 快捷键说明

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