diff --git a/src/xercesc/internal/DGXMLScanner.cpp b/src/xercesc/internal/DGXMLScanner.cpp index 3934d1af04c78120138d731a0fbfd6be2fecfe7d..19bc879fd2c55ee3379988e924b596a9f8980421 100644 --- a/src/xercesc/internal/DGXMLScanner.cpp +++ b/src/xercesc/internal/DGXMLScanner.cpp @@ -758,6 +758,8 @@ void DGXMLScanner::scanEndTag(bool& gotData) ? topElem->fThisElement->getElementName()->getPrefix() : XMLUni::fgZeroLenString ); + // pass back type name information + fDocHandler->elementTypeInfo(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString); } // If this was the root, then done with content @@ -1591,6 +1593,8 @@ bool DGXMLScanner::scanStartTag(bool& gotData) , (fDoNamespaces) ? elemDecl->getElementName()->getPrefix() : XMLUni::fgZeroLenString ); + // pass back type name information + fDocHandler->elementTypeInfo(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString); } // Pop the element stack back off since it'll never be used now diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp index b71289ee76e909d7b31a18f8538bca68e0f8e45e..1450765568da06a06fa846b2b132a66d45fad66c 100644 --- a/src/xercesc/internal/IGXMLScanner.cpp +++ b/src/xercesc/internal/IGXMLScanner.cpp @@ -1020,6 +1020,8 @@ void IGXMLScanner::scanEndTag(bool& gotData) XMLElementDecl* tempElement = topElem->fThisElement; if (fDoNamespaces && fGrammarType == Grammar::SchemaGrammarType) { + // reset error occurred + fPSVIElemContext.fErrorOccurred = fErrorStack->pop(); const XMLCh* rawNameBuf = fQNameBuf.getRawBuffer(); if ((topUri != uriId) || (!XMLString::equals(tempElement->getBaseName(), &rawNameBuf[prefixColonPos + 1]))) { @@ -1058,16 +1060,19 @@ void IGXMLScanner::scanEndTag(bool& gotData) ); } - if (fPSVIHandler && fGrammarType == Grammar::SchemaGrammarType) + if (fGrammarType == Grammar::SchemaGrammarType) { if (fValidate && topElem->fThisElement->isDeclared()) { fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator(); fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo(); - fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); + if(fPSVIHandler) + { + fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); - if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) - fPSVIElemContext.fNormalizedValue = 0; + if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) + fPSVIElemContext.fNormalizedValue = 0; + } } else { @@ -1125,14 +1130,14 @@ void IGXMLScanner::scanEndTag(bool& gotData) if (fGrammarType == Grammar::SchemaGrammarType) { + if (((SchemaValidator*) fValidator)->getErrorOccurred()) + fPSVIElemContext.fErrorOccurred = true; + else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) + psviMemberType = fValidationContext->getValidatingMemberType(); if (fPSVIHandler) { fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified(); - if (((SchemaValidator*) fValidator)->getErrorOccurred()) - fPSVIElemContext.fErrorOccurred = true; - else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) - psviMemberType = fValidationContext->getValidatingMemberType(); } // call matchers and de-activate context @@ -1209,14 +1214,60 @@ void IGXMLScanner::scanEndTag(bool& gotData) , isRoot , fPrefixBuf.getRawBuffer() ); + // pass information about type info: + if(fGrammarType == Grammar::SchemaGrammarType) + { + const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE; + const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; + if(!fPSVIElemContext.fErrorOccurred) + { + if(fPSVIElemContext.fCurrentTypeInfo != 0) + { + if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName(); + typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri(); + } + else + { + DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV; + if(actualDV) + { + if(actualDV->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = actualDV->getTypeLocalName(); + typeURI = actualDV->getTypeUri(); + } + } + } + else + { + // idiosyncratically, if there's an + // error but this element was simpleType-validated, + // the tests demand anySimpleType be returned + if(fPSVIElemContext.fCurrentDV) + typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE; + } + fDocHandler->elementTypeInfo(typeName, typeURI); + } + else + { + fDocHandler->elementTypeInfo(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString); + } } // reset xsi:type ComplexTypeInfo if (fGrammarType == Grammar::SchemaGrammarType) { ((SchemaElementDecl*)topElem->fThisElement)->reset(); if (!isRoot) + { ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))-> setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo()); + // update error information + fErrorStack->push(fErrorStack->pop() || fPSVIElemContext.fErrorOccurred); + } } // If this was the root, then done with content @@ -2544,6 +2595,9 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) } } + // this info needed for DOMTypeInfo + fPSVIElemContext.fErrorOccurred = false; + // We do something different here according to whether we found the // element or not. if (wasAdded) @@ -2570,6 +2624,7 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) { ((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL); ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);\ + fPSVIElemContext.fErrorOccurred = true; } } } @@ -2588,6 +2643,7 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) if(fGrammarType == Grammar::SchemaGrammarType) { ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID); ((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL); + fPSVIElemContext.fErrorOccurred = true; } } @@ -2631,10 +2687,8 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) if (fGrammarType == Grammar::SchemaGrammarType && fPSVIHandler) { - fErrorStack->push(fPSVIElemContext.fErrorOccurred); - fPSVIElemContext.fErrorOccurred = false; - fPSVIElemContext.fElemDepth++; + fPSVIElemContext.fElemDepth++; if (elemDecl->isDeclared()) { fPSVIElemContext.fNoneValidationDepth = fPSVIElemContext.fElemDepth; @@ -2643,8 +2697,12 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) { fPSVIElemContext.fFullValidationDepth = fPSVIElemContext.fElemDepth; + /****** + * While we report an error for historical reasons, this should + * actually result in lax assessment - NG. if (isRoot && fValidate) fPSVIElemContext.fErrorOccurred = true; + *****/ } } @@ -2652,7 +2710,7 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) if (fValidate) { fValidator->validateElement(elemDecl); - if (fPSVIHandler && fValidator->handlesSchema()) + if (fValidator->handlesSchema()) { if (((SchemaValidator*) fValidator)->getErrorOccurred()) fPSVIElemContext.fErrorOccurred = true; @@ -2813,16 +2871,20 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) fElemStack.popTop(); // reset current type info - if (fPSVIHandler && fGrammarType == Grammar::SchemaGrammarType) + DatatypeValidator* psviMemberType = 0; + if (fGrammarType == Grammar::SchemaGrammarType) { if (fValidate && elemDecl->isDeclared()) { fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator(); fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo(); - fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); + if(fPSVIHandler) + { + fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); - if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) - fPSVIElemContext.fNormalizedValue = 0; + if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) + fPSVIElemContext.fNormalizedValue = 0; + } } else { @@ -2832,7 +2894,6 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) } } - DatatypeValidator* psviMemberType = 0; // If validating, then insure that its legal to have no content if (fValidate) { @@ -2854,9 +2915,10 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) fPSVIElemContext.fErrorOccurred = true; ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID); } - else if (fPSVIHandler) + else { - fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified(); + if (fPSVIHandler) + fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified(); // note that if we're empty, won't be a current DV if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) psviMemberType = fValidationContext->getValidatingMemberType(); @@ -2931,6 +2993,48 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) , isRoot , fPrefixBuf.getRawBuffer() ); + // pass information about type info: + if(fGrammarType == Grammar::SchemaGrammarType) + { + const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE; + const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; + if(!fPSVIElemContext.fErrorOccurred) + { + if(fPSVIElemContext.fCurrentTypeInfo != 0) + { + if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName(); + typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri(); + } + else + { + DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV; + if(actualDV) + { + if(actualDV->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = actualDV->getTypeLocalName(); + typeURI = actualDV->getTypeUri(); + } + } + } + else + { + // idiosyncratically, if there's an + // error but this element was simpleType-validated, + // the tests demand anySimpleType be returned + if(fPSVIElemContext.fCurrentDV) + typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE; + } + fDocHandler->elementTypeInfo(typeName, typeURI); + } + else + { + fDocHandler->elementTypeInfo(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString); + } } // reset xsi:type ComplexTypeInfo @@ -2970,6 +3074,8 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData) fValidate = fElemStack.getValidationFlag(); } } + else // not empty + fErrorStack->push(fPSVIElemContext.fErrorOccurred); return true; } @@ -3408,9 +3514,6 @@ void IGXMLScanner::endElementPSVI(SchemaElementDecl* const elemDecl, // decrease element depth fPSVIElemContext.fElemDepth--; - // reset error occurred - fPSVIElemContext.fErrorOccurred = - fPSVIElemContext.fErrorOccurred && fErrorStack->pop(); } void IGXMLScanner::resetPSVIElemContext() diff --git a/src/xercesc/internal/IGXMLScanner2.cpp b/src/xercesc/internal/IGXMLScanner2.cpp index 267b13baeefd66044a0267225f3c8bfb477f8875..7f1a2372a9197bf37cb453a7339650633d8cc22a 100644 --- a/src/xercesc/internal/IGXMLScanner2.cpp +++ b/src/xercesc/internal/IGXMLScanner2.cpp @@ -270,10 +270,10 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs ); if(fGrammarType == Grammar::SchemaGrammarType) { ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { attrValid = PSVIItem::VALIDITY_INVALID; - fPSVIElemContext.fErrorOccurred = true; } } } @@ -292,10 +292,10 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs ); if(fGrammarType == Grammar::SchemaGrammarType) { ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { attrValid = PSVIItem::VALIDITY_INVALID; - fPSVIElemContext.fErrorOccurred = true; } } } @@ -390,7 +390,7 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID); ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL); } - if(getPSVIHandler() && fGrammarType == Grammar::SchemaGrammarType ) + if(fGrammarType == Grammar::SchemaGrammarType ) { // if we've found either an attDef or an attDefForWildCard, // then we're doing full validation and it may still be valid. @@ -398,18 +398,24 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs { if(!laxThisOne && !skipThisOne) { - attrValid = PSVIItem::VALIDITY_INVALID; fPSVIElemContext.fErrorOccurred = true; - } - else if(laxThisOne) - { - attrValid = PSVIItem::VALIDITY_NOTKNOWN; - attrAssessed = PSVIItem::VALIDATION_PARTIAL; - } - else + } + if(getPSVIHandler()) { - attrValid = PSVIItem::VALIDITY_NOTKNOWN; - attrAssessed = PSVIItem::VALIDATION_NONE; + if(!laxThisOne && !skipThisOne) + { + attrValid = PSVIItem::VALIDITY_INVALID; + } + else if(laxThisOne) + { + attrValid = PSVIItem::VALIDITY_NOTKNOWN; + attrAssessed = PSVIItem::VALIDATION_PARTIAL; + } + else + { + attrValid = PSVIItem::VALIDITY_NOTKNOWN; + attrAssessed = PSVIItem::VALIDATION_NONE; + } } } } @@ -487,10 +493,11 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , elemDecl ); attrValidator = ((SchemaValidator*)fValidator)->getMostRecentAttrValidator(); - if(getPSVIHandler() && ((SchemaValidator *)fValidator)->getErrorOccurred()) + if(((SchemaValidator *)fValidator)->getErrorOccurred()) { fPSVIElemContext.fErrorOccurred = true; - attrValid = PSVIItem::VALIDITY_INVALID; + if(getPSVIHandler()) + attrValid = PSVIItem::VALIDITY_INVALID; } } else // no decl; default DOMTypeInfo to anySimpleType @@ -546,9 +553,12 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs if(fGrammarType == Grammar::SchemaGrammarType) { attrValidator = ((SchemaValidator*)fValidator)->getMostRecentAttrValidator(); - if (getPSVIHandler() - && ((SchemaValidator *)fValidator)->getErrorOccurred()) - attrValid = PSVIItem::VALIDITY_INVALID; + if(((SchemaValidator *)fValidator)->getErrorOccurred()) + { + fPSVIElemContext.fErrorOccurred = true; + if (getPSVIHandler()) + attrValid = PSVIItem::VALIDITY_INVALID; + } } } else if(fGrammarType == Grammar::SchemaGrammarType) @@ -889,6 +899,7 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs { ((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID); ((SchemaElementDecl *)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { QName *attQName = ((SchemaAttDef *)curDef)->getAttName(); @@ -899,7 +910,6 @@ IGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs fURIStringPool->getValueForId(attQName->getURI()) ); prohibitedAttr->updateValidity(PSVIItem::VALIDITY_INVALID); - fPSVIElemContext.fErrorOccurred = true; } } } @@ -1248,16 +1258,14 @@ void IGXMLScanner::scanReset(const InputSource& src) fSeeXsi = false; // Reset PSVI context - if (fPSVIHandler) - { - if (!fPSVIElement) - fPSVIElement = new (fMemoryManager) PSVIElement(fMemoryManager); + // note that we always need this around for DOMTypeInfo + if (!fPSVIElement) + fPSVIElement = new (fMemoryManager) PSVIElement(fMemoryManager); - if (!fErrorStack) - fErrorStack = new (fMemoryManager) ValueStackOf<bool>(8, fMemoryManager); + if (!fErrorStack) + fErrorStack = new (fMemoryManager) ValueStackOf<bool>(8, fMemoryManager); - resetPSVIElemContext(); - } + resetPSVIElemContext(); // Reset the validators fDTDValidator->reset(); diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp index 190973421dbe199d6f15308e41ae8dde2104255f..057aaae34d650dbb23b1cc2a691d93c9c2b00249 100644 --- a/src/xercesc/internal/SGXMLScanner.cpp +++ b/src/xercesc/internal/SGXMLScanner.cpp @@ -941,6 +941,9 @@ void SGXMLScanner::scanEndTag(bool& gotData) XMLElementDecl* tempElement = topElem->fThisElement; const XMLCh* rawNameBuf = fQNameBuf.getRawBuffer(); + // reset error occurred + fPSVIElemContext.fErrorOccurred = fErrorStack->pop(); + if ((topUri != uriId) || (!XMLString::equals(tempElement->getBaseName(), &rawNameBuf[prefixColonPos + 1]))) { @@ -968,24 +971,24 @@ void SGXMLScanner::scanEndTag(bool& gotData) ); } - if (fPSVIHandler) + if (fValidate && topElem->fThisElement->isDeclared()) { - if (fValidate && topElem->fThisElement->isDeclared()) + fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator(); + fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo(); + if (fPSVIHandler) { - fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator(); - fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo(); fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) fPSVIElemContext.fNormalizedValue = 0; } - else - { - fPSVIElemContext.fCurrentDV = 0; - fPSVIElemContext.fCurrentTypeInfo = 0; - fPSVIElemContext.fNormalizedValue = 0; - } + } + else + { + fPSVIElemContext.fCurrentDV = 0; + fPSVIElemContext.fCurrentTypeInfo = 0; + fPSVIElemContext.fNormalizedValue = 0; } // If validation is enabled, then lets pass him the list of children and @@ -1036,14 +1039,12 @@ void SGXMLScanner::scanEndTag(bool& gotData) } // update PSVI info + if (((SchemaValidator*) fValidator)->getErrorOccurred()) + fPSVIElemContext.fErrorOccurred = true; + else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) + psviMemberType = fValidationContext->getValidatingMemberType(); if (fPSVIHandler) - { fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified(); - if (((SchemaValidator*) fValidator)->getErrorOccurred()) - fPSVIElemContext.fErrorOccurred = true; - else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) - psviMemberType = fValidationContext->getValidatingMemberType(); - } // call matchers and de-activate context int oldCount = fMatcherStack->getMatcherCount(); @@ -1116,13 +1117,52 @@ void SGXMLScanner::scanEndTag(bool& gotData) , isRoot , fPrefixBuf.getRawBuffer() ); + // pass information about type info: + const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE; + const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; + if(!fPSVIElemContext.fErrorOccurred) + { + if(fPSVIElemContext.fCurrentTypeInfo != 0) + { + if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName(); + typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri(); + } + else + { + DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV; + if(actualDV) + { + if(actualDV->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = actualDV->getTypeLocalName(); + typeURI = actualDV->getTypeUri(); + } + } + } + else + { + // idiosyncratically, if there's an + // error but this element was simpleType-validated, + // the tests demand anySimpleType be returned + if(fPSVIElemContext.fCurrentDV) + typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE; + } + fDocHandler->elementTypeInfo(typeName, typeURI); } // reset xsi:type ComplexTypeInfo ((SchemaElementDecl*)topElem->fThisElement)->reset(); if (!isRoot) + { ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))-> setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo()); + // update error information + fErrorStack->push(fErrorStack->pop() || fPSVIElemContext.fErrorOccurred); + } // If this was the root, then done with content gotData = !isRoot; @@ -1508,6 +1548,8 @@ bool SGXMLScanner::scanStartTag(bool& gotData) } } + // this info needed for DOMTypeInfo + fPSVIElemContext.fErrorOccurred = false; // We do something different here according to whether we found the // element or not. @@ -1534,6 +1576,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData) , elemDecl->getFullName() ); ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; } } else @@ -1550,6 +1593,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData) if(elemDecl->getCreateReason() == XMLElementDecl::NoReason) { ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID); ((SchemaElementDecl *)(elemDecl))->setValidationAttempted(PSVIDefs::FULL); + fPSVIElemContext.fErrorOccurred = true; } if (laxThisOne) { fValidate = false; @@ -1589,8 +1633,6 @@ bool SGXMLScanner::scanStartTag(bool& gotData) if (fPSVIHandler) { - fErrorStack->push(fPSVIElemContext.fErrorOccurred); - fPSVIElemContext.fErrorOccurred = false; fPSVIElemContext.fElemDepth++; if (elemDecl->isDeclared()) @@ -1601,8 +1643,12 @@ bool SGXMLScanner::scanStartTag(bool& gotData) { fPSVIElemContext.fFullValidationDepth = fPSVIElemContext.fElemDepth; + /****** + * While we report an error for historical reasons, this should + * actually result in lax assessment - NG. if (isRoot && fValidate) fPSVIElemContext.fErrorOccurred = true; + ******/ } } @@ -1610,11 +1656,8 @@ bool SGXMLScanner::scanStartTag(bool& gotData) if (fValidate) { fValidator->validateElement(elemDecl); - if (fPSVIHandler) - { - if (((SchemaValidator*) fValidator)->getErrorOccurred()) - fPSVIElemContext.fErrorOccurred = true; - } + if (((SchemaValidator*) fValidator)->getErrorOccurred()) + fPSVIElemContext.fErrorOccurred = true; } ComplexTypeInfo* typeinfo = (fValidate) @@ -1757,16 +1800,20 @@ bool SGXMLScanner::scanStartTag(bool& gotData) fElemStack.popTop(); // reset current type info - if (fPSVIHandler && fGrammarType == Grammar::SchemaGrammarType) + DatatypeValidator* psviMemberType = 0; + if (fGrammarType == Grammar::SchemaGrammarType) { if (fValidate && elemDecl->isDeclared()) { fPSVIElemContext.fCurrentDV = ((SchemaValidator*) fValidator)->getCurrentDatatypeValidator(); fPSVIElemContext.fCurrentTypeInfo = ((SchemaValidator*) fValidator)->getCurrentTypeInfo(); - fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); + if(fPSVIHandler) + { + fPSVIElemContext.fNormalizedValue = ((SchemaValidator*) fValidator)->getNormalizedValue(); - if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) - fPSVIElemContext.fNormalizedValue = 0; + if (XMLString::equals(fPSVIElemContext.fNormalizedValue, XMLUni::fgZeroLenString)) + fPSVIElemContext.fNormalizedValue = 0; + } } else { @@ -1777,7 +1824,6 @@ bool SGXMLScanner::scanStartTag(bool& gotData) } // If validating, then insure that its legal to have no content - DatatypeValidator* psviMemberType = 0; if (fValidate) { const int res = fValidator->checkContent(elemDecl, 0, 0); @@ -1794,13 +1840,15 @@ bool SGXMLScanner::scanStartTag(bool& gotData) ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID); } - if (fPSVIHandler) + if (((SchemaValidator*) fValidator)->getErrorOccurred()) + fPSVIElemContext.fErrorOccurred = true; + // note that if we're empty, won't be a current DV + else { - if (((SchemaValidator*) fValidator)->getErrorOccurred()) - fPSVIElemContext.fErrorOccurred = true; - // note that if we're empty, won't be a current DV - else if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) - psviMemberType = fValidationContext->getValidatingMemberType(); + if (fPSVIHandler) + fPSVIElemContext.fIsSpecified = ((SchemaValidator*) fValidator)->getIsElemSpecified(); + if (fPSVIElemContext.fCurrentDV && fPSVIElemContext.fCurrentDV->getType() == DatatypeValidator::Union) + psviMemberType = fValidationContext->getValidatingMemberType(); } // call matchers and de-activate context @@ -1870,6 +1918,41 @@ bool SGXMLScanner::scanStartTag(bool& gotData) , isRoot , fPrefixBuf.getRawBuffer() ); + // pass information about type info: + const XMLCh *typeName = SchemaSymbols::fgATTVAL_ANYTYPE; + const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; + if(!fPSVIElemContext.fErrorOccurred) + { + if(fPSVIElemContext.fCurrentTypeInfo != 0) + { + if(fPSVIElemContext.fCurrentTypeInfo->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = fPSVIElemContext.fCurrentTypeInfo->getTypeLocalName(); + typeURI = fPSVIElemContext.fCurrentTypeInfo->getTypeUri(); + } + else + { + DatatypeValidator *actualDV = (psviMemberType)?psviMemberType:fPSVIElemContext.fCurrentDV; + if(actualDV) + { + if(actualDV->getAnonymous()) + typeName = XMLUni::fgZeroLenString; + else + typeName = actualDV->getTypeLocalName(); + typeURI = actualDV->getTypeUri(); + } + } + } + else + { + // idiosyncratically, if there's an + // error but this element was simpleType-validated, + // the tests demand anySimpleType be returned + if(fPSVIElemContext.fCurrentDV) + typeName = SchemaSymbols::fgDT_ANYSIMPLETYPE; + } + fDocHandler->elementTypeInfo(typeName, typeURI); } // reset xsi:type ComplexTypeInfo @@ -1892,6 +1975,8 @@ bool SGXMLScanner::scanStartTag(bool& gotData) fValidate = fElemStack.getValidationFlag(); } } + else // not empty + fErrorStack->push(fPSVIElemContext.fErrorOccurred); return true; } @@ -2329,10 +2414,10 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , attDef->getFullName() ); ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { attrValid = PSVIItem::VALIDITY_INVALID; - fPSVIElemContext.fErrorOccurred = true; } } } @@ -2348,10 +2433,10 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , attDef->getFullName() ); ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { attrValid = PSVIItem::VALIDITY_INVALID; - fPSVIElemContext.fErrorOccurred = true; } } } @@ -2420,16 +2505,19 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL); } - if(getPSVIHandler()) + // if we've found either an attDef or an attDefForWildCard, + // then we're doing full validation and it may still be valid. + if(!attDef && !attDefForWildCard) { - // if we've found either an attDef or an attDefForWildCard, - // then we're doing full validation and it may still be valid. - if(!attDef && !attDefForWildCard) + if(!laxThisOne && !skipThisOne) + { + fPSVIElemContext.fErrorOccurred = true; + } + if(getPSVIHandler()) { if(!laxThisOne && !skipThisOne) { attrValid = PSVIItem::VALIDITY_INVALID; - fPSVIElemContext.fErrorOccurred = true; } else if(laxThisOne) { @@ -2516,10 +2604,11 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , elemDecl ); attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator(); - if(getPSVIHandler() && ((SchemaValidator *)fValidator)->getErrorOccurred()) + if(((SchemaValidator *)fValidator)->getErrorOccurred()) { - attrValid = PSVIItem::VALIDITY_INVALID; fPSVIElemContext.fErrorOccurred = true; + if(getPSVIHandler()) + attrValid = PSVIItem::VALIDITY_INVALID; } } else // no decl; default DOMTypeInfo to anySimpleType @@ -2571,10 +2660,11 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , elemDecl ); attrValidator = ((SchemaValidator *)fValidator)->getMostRecentAttrValidator(); - if(getPSVIHandler() && ((SchemaValidator *)fValidator)->getErrorOccurred()) + if(((SchemaValidator *)fValidator)->getErrorOccurred()) { - attrValid = PSVIItem::VALIDITY_INVALID; fPSVIElemContext.fErrorOccurred = true; + if(getPSVIHandler()) + attrValid = PSVIItem::VALIDITY_INVALID; } } else @@ -2867,6 +2957,7 @@ SGXMLScanner::buildAttList(const RefVectorOf<KVStringPair>& providedAttrs , curDef->getFullName() ); ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::INVALID); + fPSVIElemContext.fErrorOccurred = true; if (getPSVIHandler()) { QName *attQName = ((SchemaAttDef *)curDef)->getAttName(); @@ -3209,16 +3300,14 @@ void SGXMLScanner::scanReset(const InputSource& src) fDoSchema = true; // Reset PSVI context - if (fPSVIHandler) - { - if (!fPSVIElement) - fPSVIElement = new (fMemoryManager) PSVIElement(fMemoryManager); + // Note that we always need this around for DOMTypeInfo + if (!fPSVIElement) + fPSVIElement = new (fMemoryManager) PSVIElement(fMemoryManager); - if (!fErrorStack) - fErrorStack = new (fMemoryManager) ValueStackOf<bool>(8, fMemoryManager); + if (!fErrorStack) + fErrorStack = new (fMemoryManager) ValueStackOf<bool>(8, fMemoryManager); - resetPSVIElemContext(); - } + resetPSVIElemContext(); // Reset the validators fSchemaValidator->reset(); @@ -4833,9 +4922,6 @@ void SGXMLScanner::endElementPSVI(SchemaElementDecl* const elemDecl, // decrease element depth fPSVIElemContext.fElemDepth--; - // reset error occurred - fPSVIElemContext.fErrorOccurred = - fPSVIElemContext.fErrorOccurred && fErrorStack->pop(); } void SGXMLScanner::resetPSVIElemContext()