gareth 2003/01/29 11:59:36
Modified: c/src/xercesc/internal IGXMLScanner.cpp IGXMLScanner.hpp
IGXMLScanner2.cpp SGXMLScanner.cpp SGXMLScanner.hpp
Log:
we now detect when elements and attributes are validated/ the result of the
validation and store that information.
Revision Changes Path
1.7 +100 -21 xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
Index: IGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- IGXMLScanner.cpp 23 Jan 2003 19:54:34 -0000 1.6
+++ IGXMLScanner.cpp 29 Jan 2003 19:59:35 -0000 1.7
@@ -1009,13 +1009,8 @@
}
}
- // reset xsi:type ComplexTypeInfo
- if (fGrammarType == Grammar::SchemaGrammarType) {
- ((SchemaElementDecl*)topElem->fThisElement)->setXsiComplexTypeInfo(0);
- if (!isRoot)
-
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->setXsiComplexTypeInfo(
- ((SchemaValidator*)fValidator)->getCurrentTypeInfo());
+ if (fGrammarType == Grammar::SchemaGrammarType) {
// call matchers and de-activate context
int oldCount = fMatcherStack->getMatcherCount();
@@ -1064,7 +1059,9 @@
}
}
}
-
+ if(!isRoot && fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromElement(topElem->fThisElement,
fGrammarType);
+
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
{
@@ -1077,6 +1074,14 @@
);
}
+ // reset xsi:type ComplexTypeInfo
+ if (fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaElementDecl*)topElem->fThisElement)->reset();
+ if (!isRoot)
+ ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
+
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
+ }
+
// If this was the root, then done with content
gotData = !isRoot;
@@ -1799,6 +1804,7 @@
// XML 1.0 Section 2.9
// Document is standalone, so attributes must not be
defaulted.
fValidator->emitError(XMLValid::NoDefAttForStandalone,
curDef.getFullName(), elemDecl->getFullName());
+
}
}
}
@@ -2056,6 +2062,9 @@
// generic element decl object. We tell him to fault one in if he does
// not find it.
bool wasAdded = false;
+ bool errorBeforeElementFound = false;
+ bool laxBeforeElementFound = false;
+
const XMLCh* nameRawBuf = &qnameRawBuf[prefixColonPos + 1];
const XMLCh* original_uriStr = fGrammar->getTargetNamespace();
unsigned orgGrammarUri = fURIStringPool->getId(original_uriStr);
@@ -2074,14 +2083,18 @@
if (!elemDecl && (orgGrammarUri != uriId)) {
// not found, switch to the specified grammar
const XMLCh* uriStr = getURIText(uriId);
- if (!switchGrammar(uriStr) && fValidate && !laxThisOne)
+ bool errorCondition = !switchGrammar(uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,uriStr
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -2113,13 +2126,17 @@
, currentScope
);
- if (elemDecl && elemDecl->getCreateReason() !=
XMLElementDecl::JustFaultIn && fValidate) {
+ bool errorCondition = elemDecl && elemDecl->getCreateReason() !=
XMLElementDecl::JustFaultIn;
+ if (errorCondition && fValidate) {
fValidator->emitError
(
XMLValid::ElementNotUnQualified
, elemDecl->getFullName()
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
}
}
@@ -2153,14 +2170,18 @@
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
//not found, switch grammar and try globalNS
- if (!switchGrammar(XMLUni::fgZeroLenString) && fValidate && !laxThisOne)
+ bool errorCondition = !switchGrammar(XMLUni::fgZeroLenString) &&
fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, XMLUni::fgZeroLenString
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -2184,14 +2205,21 @@
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
// still Not found in specified uri
// go to original Grammar again to see if element needs to be fully
qualified.
- if (!switchGrammar(original_uriStr) && fValidate && !laxThisOne)
+ const XMLCh* uriStr = getURIText(orgGrammarUri);
+ bool errorCondition = !switchGrammar(original_uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
+
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,original_uriStr
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -2207,6 +2235,7 @@
XMLValid::ElementNotQualified
, elemDecl->getFullName()
);
+ errorBeforeElementFound = true;
}
}
}
@@ -2233,6 +2262,9 @@
fValidate = false;
fElemStack.setValidationFlag(fValidate);
}
+ else if(fGrammarType == Grammar::SchemaGrammarType && fValidate) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
+ }
// If validating then emit an error
if (fValidate)
@@ -2246,10 +2278,20 @@
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
}
else
{
+ if(!laxBeforeElementFound && fGrammarType == Grammar::SchemaGrammarType) {
+ if (fValidate) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::VALID);
+ }
+ }
+
// If its not marked declared and validating, then emit an error
if (!elemDecl->isDeclared()) {
if (laxThisOne) {
@@ -2257,20 +2299,32 @@
fElemStack.setValidationFlag(fValidate);
}
- if (fValidate)
+ if (fValidate)
{
fValidator->emitError
(
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
+
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::INVALID);
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
+ }
}
}
- if (fGrammarType == Grammar::SchemaGrammarType)
+ if (fGrammarType == Grammar::SchemaGrammarType) {
((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
+ ((SchemaElementDecl*)elemDecl)->setXsiSimpleTypeInfo(0);
+ }
+ }
+
+ if(errorBeforeElementFound && fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
+
// Now we can update the element stack to set the current element
// decl. We expanded the stack above, but couldn't store the element
// decl because we didn't know it yet.
@@ -2298,13 +2352,25 @@
XMLBuffer prefixBuf(comma+1);
prefixBuf.append(typeName, comma);
const XMLCh* uriStr = prefixBuf.getRawBuffer();
- if (!switchGrammar(uriStr) && fValidate && !laxThisOne)
+
+ bool errorCondition = !switchGrammar(uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, prefixBuf.getRawBuffer()
);
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::INVALID);
+
+ }
+ else if(errorCondition) {
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::NONE);
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::UNKNOWN);
+ }
}
}
}
@@ -2336,6 +2402,10 @@
// XMLValidator::checkRootElement
if (fValidatorFromUser &&
!fValidator->checkRootElement(elemDecl->getId()))
fValidator->emitError(XMLValid::RootElemNotLikeDocType);
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
+
}
}
else if (parentValidation)
@@ -2417,16 +2487,13 @@
, elemDecl->getFullName()
, elemDecl->getFormattedContentModel()
);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::INVALID);
+
}
if (fGrammarType == Grammar::SchemaGrammarType) {
- // reset xsi:type ComplexTypeInfo
- ((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
- if (!isRoot)
-
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->setXsiComplexTypeInfo(
- ((SchemaValidator*)fValidator)->getCurrentTypeInfo());
-
// call matchers and de-activate context
int oldCount = fMatcherStack->getMatcherCount();
@@ -2475,6 +2542,10 @@
}
}
+ if(!isRoot && fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromElement(elemDecl,
fGrammarType);
+
+
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
{
@@ -2485,6 +2556,14 @@
, isRoot
, fPrefixBuf.getRawBuffer()
);
+ }
+
+ // reset xsi:type ComplexTypeInfo
+ if (fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaElementDecl*)elemDecl)->reset();
+ if (!isRoot)
+ ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
+
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
}
// If the elem stack is empty, then it was an empty root
1.4 +4 -0 xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp
Index: IGXMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- IGXMLScanner.hpp 15 Jan 2003 15:49:49 -0000 1.3
+++ IGXMLScanner.hpp 29 Jan 2003 19:59:35 -0000 1.4
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.4 2003/01/29 19:59:35 gareth
+ * we now detect when elements and attributes are validated/ the result of the
validation and store that information.
+ *
* Revision 1.3 2003/01/15 15:49:49 knoaman
* Change constant declaration name to match its value.
*
@@ -75,6 +78,7 @@
#include <xercesc/internal/ElemStack.hpp>
#include <xercesc/util/KVStringPair.hpp>
#include <xercesc/validators/common/Grammar.hpp>
+#include <xercesc/validators/schema/SchemaElementDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
1.10 +110 -21 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp
Index: IGXMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- IGXMLScanner2.cpp 17 Jan 2003 19:13:21 -0000 1.9
+++ IGXMLScanner2.cpp 29 Jan 2003 19:59:35 -0000 1.10
@@ -236,6 +236,9 @@
XMLValid::AttributeNotQualified
, attDef->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
}
}
else {
@@ -249,6 +252,9 @@
XMLValid::AttributeNotUnQualified
, attDef->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
}
}
}
@@ -271,6 +277,14 @@
);
}
+ if(!skipThisOne && fGrammarType == Grammar::SchemaGrammarType) {
+ //we may have set it to invalid already, but this is the first time
we are guarenteed to have the attDef
+ if(((SchemaAttDef *)(attDef))->getValidity() != PSVIDefs::INVALID)
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID);
+
+ ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL);
+ }
+
if (wasAdded)
{
// This is to tell the Validator that this attribute was
@@ -278,8 +292,9 @@
attDef->setCreateReason(XMLAttDef::JustFaultIn);
}
- if (fValidate && !attDefForWildCard && !skipThisOne && !laxThisOne &&
- attDef->getCreateReason() == XMLAttDef::JustFaultIn &&
!attDef->getProvided())
+ bool errorCondition = fValidate && !attDefForWildCard &&
+ attDef->getCreateReason() == XMLAttDef::JustFaultIn &&
!attDef->getProvided();
+ if (errorCondition && !skipThisOne && !laxThisOne)
{
//
// Its not valid for this element, so issue an error if we are
@@ -304,18 +319,29 @@
, bufMsg.getRawBuffer()
, elemDecl->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
}
+ else if(errorCondition && laxThisOne && fGrammarType ==
Grammar::SchemaGrammarType) {
+ ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::NONE);
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::UNKNOWN);
+ }
+
// If its already provided, then there are more than one of
// this attribute in this start tag, so emit an error.
if (attDef->getProvided())
{
emitError
- (
+ (
XMLErrs::AttrAlreadyUsedInSTag
, attDef->getFullName()
, elemDecl->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
}
else
{
@@ -326,6 +352,7 @@
// don't care about the return status here. If it failed, an error
// was issued, which is all we care about.
if (attDefForWildCard) {
+ ((SchemaAttDef*)attDef)->setAnyDatatypeValidator(((SchemaAttDef*)
attDefForWildCard)->getDatatypeValidator());
normalizeAttValue
(
attDefForWildCard
@@ -357,6 +384,11 @@
// Save the type for later use
attType = attDefForWildCard->getType();
+
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
+
}
else {
normalizeAttValue
@@ -394,6 +426,12 @@
// Save the type for later use
attType = attDef->getType();
+
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
+
+
}
}
else
@@ -456,11 +494,16 @@
while (attDefList.hasMoreElements())
{
// Get the current att def, for convenience and its def type
- const XMLAttDef& curDef = attDefList.nextElement();
- const XMLAttDef::DefAttTypes defType = curDef.getDefaultType();
+ const XMLAttDef *curDef = &attDefList.nextElement();
+ const XMLAttDef::DefAttTypes defType = curDef->getDefaultType();
- if (!curDef.getProvided())
+ if (!curDef->getProvided())
{
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)curDef)->setValidationAttempted(PSVIDefs::FULL);
+ ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::VALID);
+ }
+
//the attributes is not provided
if (fValidate)
{
@@ -472,17 +515,21 @@
fValidator->emitError
(
XMLValid::RequiredAttrNotProvided
- , curDef.getFullName()
+ , curDef->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaAttDef
*)(curDef))->setValidity(PSVIDefs::INVALID);
}
else if ((defType == XMLAttDef::Default) ||
(defType == XMLAttDef::Fixed) )
{
- if (fStandalone && curDef.isExternal())
+ 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());
+ fValidator->emitError(XMLValid::NoDefAttForStandalone,
curDef->getFullName(), elemDecl->getFullName());
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaAttDef
*)(curDef))->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -497,8 +544,8 @@
{
fValidator->validateAttrValue
(
- &curDef
- , curDef.getValue()
+ curDef
+ , curDef->getValue()
, false
, elemDecl
);
@@ -508,13 +555,13 @@
if (retCount >= curAttListSize)
{
curAtt = new XMLAttr;
- fValidator->faultInAttr(*curAtt, curDef);
+ fValidator->faultInAttr(*curAtt, *curDef);
fAttrList->addElement(curAtt);
}
else
{
curAtt = fAttrList->elementAt(retCount);
- fValidator->faultInAttr(*curAtt, curDef);
+ fValidator->faultInAttr(*curAtt, *curDef);
}
if (fGrammarType == Grammar::DTDGrammarType)
@@ -531,17 +578,26 @@
curAtt->setSpecified(false);
retCount++;
}
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
+
}
else
{
//attribute is provided
// (schema) report error for PROHIBITED attrs that are present
(V_TAGc)
- if (defType == XMLAttDef::Prohibited && fValidate)
+ if (defType == XMLAttDef::Prohibited && fValidate) {
fValidator->emitError
(
XMLValid::ProhibitedAttributePresent
- , curDef.getFullName()
+ , curDef->getFullName()
);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
+ ((SchemaElementDecl
*)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
+ }
+ }
}
}
}
@@ -617,6 +673,10 @@
// Can't have a standalone document declaration of "yes"
if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone,
attrName);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
+
}
nextCh = chSpace;
}
@@ -652,9 +712,12 @@
{
if (!firstNonWS || (nextCh != chSpace) || (!*srcPtr) ||
fReaderMgr.getCurrentReader()->isWhitespace(*srcPtr))
{
- // Can't have a standalone document declaration of
"yes" if attribute
- // values are subject to normalisation
-
fValidator->emitError(XMLValid::NoAttNormForStandalone, attrName);
+ // Can't have a standalone document declaration of
"yes" if attribute
+ // values are subject to normalisation
+ fValidator->emitError(XMLValid::NoAttNormForStandalone,
attrName);
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
+ }
}
}
continue;
@@ -669,6 +732,10 @@
// And move up to the next character in the source
srcPtr++;
}
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromAttribute((SchemaAttDef
*)attDef);
+
return retVal;
}
@@ -926,6 +993,8 @@
{
// They definitely cannot handle any type of char data
fValidator->emitError(XMLValid::NoCharDataInCM);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
else if (fReaderMgr.getCurrentReader()->isAllSpaces(rawBuf, len))
{
@@ -1017,6 +1086,8 @@
else
{
fValidator->emitError(XMLValid::NoCharDataInCM);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -1306,8 +1377,10 @@
{
const XMLCh* newUri =
root->getAttribute(SchemaSymbols::fgATT_TARGETNAMESPACE);
if (!XMLString::equals(newUri, uri)) {
- if (fValidate)
+ if (fValidate) {
fValidator->emitError(XMLValid::WrongTargetNamespace, loc,
uri);
+ }
+
grammar = fGrammarResolver->getGrammar(newUri);
}
@@ -1803,6 +1876,10 @@
// Can't have a standalone document declaration of
"yes" if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone, attrName);
+
+ if(fGrammarType == Grammar::SchemaGrammarType) {
+ ((SchemaAttDef
*)attDef)->setValidity(PSVIDefs::INVALID);
+ }
}
nextCh = chSpace;
}
@@ -1853,6 +1930,10 @@
if (secondCh)
toFill.append(secondCh);
+
+
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromAttribute((SchemaAttDef
*)attDef);
}
}
catch(const EndOfEntityException&)
@@ -1934,6 +2015,8 @@
// Error - standalone should have a value of "no" as whitespace
detected in an
// element type with element content whose element declaration
was external
fValidator->emitError(XMLValid::NoWSForStandalone);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -2027,6 +2110,8 @@
{
// They definitely cannot handle any type of char data
fValidator->emitError(XMLValid::NoCharDataInCM);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
@@ -2224,6 +2309,8 @@
// element type with element content whose element declaration
was external
//
fValidator->emitError(XMLValid::NoWSForStandalone);
+ if(fGrammarType == Grammar::SchemaGrammarType)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -2434,9 +2521,11 @@
// This is a case where namespaces is on with a DTD grammar.
tempGrammar = fDTDGrammar;
}
- if (!tempGrammar)
+ if (!tempGrammar) {
return false;
+ }
else {
+
fGrammar = tempGrammar;
fGrammarType = fGrammar->getGrammarType();
if (fGrammarType == Grammar::SchemaGrammarType &&
!fValidator->handlesSchema()) {
1.13 +152 -38 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp
Index: SGXMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SGXMLScanner.cpp 23 Jan 2003 19:54:35 -0000 1.12
+++ SGXMLScanner.cpp 29 Jan 2003 19:59:35 -0000 1.13
@@ -954,14 +954,9 @@
, topElem->fThisElement->getFormattedContentModel()
);
}
+
}
- // reset xsi:type ComplexTypeInfo
- ((SchemaElementDecl*)topElem->fThisElement)->setXsiComplexTypeInfo(0);
- if (!isRoot)
-
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->setXsiComplexTypeInfo(
- ((SchemaValidator*)fValidator)->getCurrentTypeInfo());
-
// call matchers and de-activate context
int oldCount = fMatcherStack->getMatcherCount();
@@ -1009,6 +1004,8 @@
fValueStoreCache->endElement();
}
}
+ if(!isRoot)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromElement(topElem->fThisElement,
fGrammarType);
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
@@ -1022,6 +1019,13 @@
);
}
+
+ // reset xsi:type ComplexTypeInfo
+ ((SchemaElementDecl*)topElem->fThisElement)->reset();
+ if (!isRoot)
+ ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
+
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
+
// If this was the root, then done with content
gotData = !isRoot;
@@ -1176,6 +1180,8 @@
// not find it.
XMLElementDecl* elemDecl = 0;
bool wasAdded = false;
+ bool errorBeforeElementFound = false;
+ bool laxBeforeElementFound = false;
const XMLCh* nameRawBuf = &qnameRawBuf[prefixColonPos + 1];
const XMLCh* original_uriStr = fGrammar->getTargetNamespace();
unsigned orgGrammarUri = fURIStringPool->getId(original_uriStr);
@@ -1194,14 +1200,18 @@
if (!elemDecl && (orgGrammarUri != uriId)) {
// not found, switch to the specified grammar
const XMLCh* uriStr = getURIText(uriId);
- if (!switchGrammar(uriStr) && fValidate && !laxThisOne)
+ bool errorCondition = !switchGrammar(uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,uriStr
);
- }
+ errorBeforeElementFound = true;
+ }
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -1233,13 +1243,18 @@
, currentScope
);
- if (elemDecl && elemDecl->getCreateReason() !=
XMLElementDecl::JustFaultIn && fValidate) {
+ bool errorCondition = elemDecl && elemDecl->getCreateReason() !=
XMLElementDecl::JustFaultIn;
+ if (errorCondition && fValidate) {
fValidator->emitError
(
XMLValid::ElementNotUnQualified
, elemDecl->getFullName()
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
+
}
}
@@ -1273,14 +1288,19 @@
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
//not found, switch grammar and try globalNS
- if (!switchGrammar(XMLUni::fgZeroLenString) && fValidate && !laxThisOne)
+ bool errorCondition = !switchGrammar(XMLUni::fgZeroLenString) &&
fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, XMLUni::fgZeroLenString
);
+ errorBeforeElementFound = true;
+
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -1304,14 +1324,19 @@
if (!elemDecl && orgGrammarUri != fEmptyNamespaceId) {
// still Not found in specified uri
// go to original Grammar again to see if element needs to be fully
qualified.
- if (!switchGrammar(original_uriStr) && fValidate && !laxThisOne)
+ const XMLCh* uriStr = getURIText(orgGrammarUri);
+ bool errorCondition = !switchGrammar(original_uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
,original_uriStr
);
+ errorBeforeElementFound = true;
}
+ else if(errorCondition)
+ laxBeforeElementFound = true;
elemDecl = fGrammar->getElemDecl
(
@@ -1327,6 +1352,7 @@
XMLValid::ElementNotQualified
, elemDecl->getFullName()
);
+ errorBeforeElementFound = true;
}
}
}
@@ -1342,9 +1368,11 @@
, currentScope
, true);
wasAdded = true;
+
}
}
+
// We do something different here according to whether we found the
// element or not.
if (wasAdded)
@@ -1353,6 +1381,9 @@
fValidate = false;
fElemStack.setValidationFlag(fValidate);
}
+ else if(fValidate) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
+ }
// If validating then emit an error
if (fValidate)
@@ -1366,28 +1397,45 @@
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
+
}
}
else
{
+ if(!laxBeforeElementFound) {
+ if (fValidate) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::VALID);
+ }
+ }
+
// If its not marked declared and validating, then emit an error
if (!elemDecl->isDeclared()) {
if (laxThisOne) {
fValidate = false;
- fElemStack.setValidationFlag(fValidate);
+ fElemStack.setValidationFlag(fValidate);
}
-
+
if (fValidate)
- {
+ {
fValidator->emitError
(
XMLValid::ElementNotDefined
, elemDecl->getFullName()
);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::FULL);
}
}
((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
+ ((SchemaElementDecl*)elemDecl)->setXsiSimpleTypeInfo(0);
+ }
+
+
+ if(errorBeforeElementFound) {
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
// Now we can update the element stack to set the current element
@@ -1417,14 +1465,24 @@
XMLBuffer prefixBuf(comma+1);
prefixBuf.append(typeName, comma);
const XMLCh* uriStr = prefixBuf.getRawBuffer();
- if (!switchGrammar(uriStr) && fValidate && !laxThisOne)
+
+ bool errorCondition = !switchGrammar(uriStr) && fValidate;
+ if (errorCondition && !laxThisOne)
{
fValidator->emitError
(
XMLValid::GrammarNotFound
, prefixBuf.getRawBuffer()
);
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::INVALID);
+
+
+ }
+ else if(errorCondition) {
+ ((SchemaElementDecl
*)(elemDecl))->setValidationAttempted(PSVIDefs::NONE);
+ ((SchemaElementDecl
*)(elemDecl))->setValidity(PSVIDefs::UNKNOWN);
}
+
}
}
}
@@ -1446,8 +1504,10 @@
{
// Some validators may also want to check the root, call the
// XMLValidator::checkRootElement
- if (fValidatorFromUser &&
!fValidator->checkRootElement(elemDecl->getId()))
+ if (fValidatorFromUser &&
!fValidator->checkRootElement(elemDecl->getId())) {
fValidator->emitError(XMLValid::RootElemNotLikeDocType);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
+ }
}
}
else if (parentValidation)
@@ -1529,14 +1589,9 @@
, elemDecl->getFullName()
, elemDecl->getFormattedContentModel()
);
+ ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
}
- // reset xsi:type ComplexTypeInfo
- ((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
- if (!isRoot)
-
((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->setXsiComplexTypeInfo(
- ((SchemaValidator*)fValidator)->getCurrentTypeInfo());
-
// call matchers and de-activate context
int oldCount = fMatcherStack->getMatcherCount();
if (oldCount || ((SchemaElementDecl*)
elemDecl)->getIdentityConstraintCount()) {
@@ -1583,6 +1638,9 @@
}
}
+ if(!isRoot)
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromElement(elemDecl,
fGrammarType);
+
// If we have a doc handler, tell it about the end tag
if (fDocHandler)
{
@@ -1595,6 +1653,12 @@
);
}
+ // reset xsi:type ComplexTypeInfo
+ ((SchemaElementDecl*)elemDecl)->reset();
+ if (!isRoot)
+ ((SchemaElementDecl*)(fElemStack.topElement()->fThisElement))->
+
setXsiComplexTypeInfo(((SchemaValidator*)fValidator)->getCurrentTypeInfo());
+
// If the elem stack is empty, then it was an empty root
if (isRoot)
gotData = false;
@@ -1991,6 +2055,7 @@
XMLValid::AttributeNotQualified
, attDef->getFullName()
);
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
}
}
else {
@@ -2004,6 +2069,7 @@
XMLValid::AttributeNotUnQualified
, attDef->getFullName()
);
+ ((SchemaAttDef
*)(attDef))->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -2026,6 +2092,14 @@
);
}
+ if(!skipThisOne && fGrammarType == Grammar::SchemaGrammarType) {
+ //we may have set it to invalid already, but this is the first time
we are guarenteed to have the attDef
+ if(((SchemaAttDef *)(attDef))->getValidity() != PSVIDefs::INVALID)
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID);
+
+ ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL);
+ }
+
if (wasAdded)
{
// This is to tell the Validator that this attribute was
@@ -2033,8 +2107,9 @@
attDef->setCreateReason(XMLAttDef::JustFaultIn);
}
- if (fValidate && !attDefForWildCard && !skipThisOne && !laxThisOne &&
- attDef->getCreateReason() == XMLAttDef::JustFaultIn &&
!attDef->getProvided())
+ bool errorCondition = fValidate && !attDefForWildCard &&
+ attDef->getCreateReason() == XMLAttDef::JustFaultIn &&
!attDef->getProvided();
+ if (errorCondition && !skipThisOne && !laxThisOne)
{
//
// Its not valid for this element, so issue an error if we are
@@ -2059,8 +2134,14 @@
, bufMsg.getRawBuffer()
, elemDecl->getFullName()
);
+ ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
+ }
+ else if(errorCondition && laxThisOne) {
+ ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::NONE);
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::UNKNOWN);
}
+
// If its already provided, then there are more than one of
// this attribute in this start tag, so emit an error.
if (attDef->getProvided())
@@ -2071,6 +2152,8 @@
, attDef->getFullName()
, elemDecl->getFullName()
);
+ ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
+
}
else
{
@@ -2081,6 +2164,7 @@
// don't care about the return status here. If it failed, an error
// was issued, which is all we care about.
if (attDefForWildCard) {
+ ((SchemaAttDef*)attDef)->setAnyDatatypeValidator(((SchemaAttDef*)
attDefForWildCard)->getDatatypeValidator());
normalizeAttValue
(
attDefForWildCard
@@ -2112,6 +2196,9 @@
// Save the type for later use
attType = attDefForWildCard->getType();
+
+ ((SchemaElementDecl
*)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
+
}
else {
normalizeAttValue
@@ -2149,6 +2236,7 @@
// Save the type for later use
attType = attDef->getType();
+ ((SchemaElementDecl
*)(elemDecl))->updateValidityFromAttribute((SchemaAttDef *)attDef);
}
}
else
@@ -2163,6 +2251,7 @@
);
}
+
// Add this attribute to the attribute list that we use to pass them
// to the handler. We reuse its existing elements but expand it as
// required.
@@ -2211,11 +2300,14 @@
while (attDefList.hasMoreElements())
{
// Get the current att def, for convenience and its def type
- const XMLAttDef& curDef = attDefList.nextElement();
- const XMLAttDef::DefAttTypes defType = curDef.getDefaultType();
+ XMLAttDef *curDef = &attDefList.nextElement();
+ const XMLAttDef::DefAttTypes defType = curDef->getDefaultType();
- if (!curDef.getProvided())
+ if (!curDef->getProvided())
{
+ ((SchemaAttDef *)curDef)->setValidationAttempted(PSVIDefs::FULL);
+ ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::VALID);
+
//the attributes is not provided
if (fValidate)
{
@@ -2227,17 +2319,20 @@
fValidator->emitError
(
XMLValid::RequiredAttrNotProvided
- , curDef.getFullName()
+ , curDef->getFullName()
);
+ ((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
}
else if ((defType == XMLAttDef::Default) ||
(defType == XMLAttDef::Fixed) )
{
- if (fStandalone && curDef.isExternal())
+ 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());
+ fValidator->emitError(XMLValid::NoDefAttForStandalone,
curDef->getFullName(), elemDecl->getFullName());
+ ((SchemaAttDef
*)(curDef))->setValidity(PSVIDefs::INVALID);
+
}
}
}
@@ -2252,8 +2347,8 @@
{
fValidator->validateAttrValue
(
- &curDef
- , curDef.getValue()
+ curDef
+ , curDef->getValue()
, false
, elemDecl
);
@@ -2263,33 +2358,39 @@
if (retCount >= curAttListSize)
{
curAtt = new XMLAttr;
- fValidator->faultInAttr(*curAtt, curDef);
+ fValidator->faultInAttr(*curAtt, *curDef);
fAttrList->addElement(curAtt);
}
else
{
curAtt = fAttrList->elementAt(retCount);
- fValidator->faultInAttr(*curAtt, curDef);
+ fValidator->faultInAttr(*curAtt, *curDef);
}
// Indicate it was not explicitly specified and bump count
curAtt->setSpecified(false);
retCount++;
}
+
+ ((SchemaElementDecl
*)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
}
else
{
//attribute is provided
// (schema) report error for PROHIBITED attrs that are present
(V_TAGc)
- if (defType == XMLAttDef::Prohibited && fValidate)
+ if (defType == XMLAttDef::Prohibited && fValidate) {
fValidator->emitError
(
XMLValid::ProhibitedAttributePresent
- , curDef.getFullName()
+ , curDef->getFullName()
);
+ ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::INVALID);
+ }
+ ((SchemaElementDecl
*)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
}
}
}
+
return retCount;
}
@@ -2362,6 +2463,7 @@
// Can't have a standalone document declaration of "yes"
if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone,
attrName);
+ ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
}
nextCh = chSpace;
}
@@ -2400,6 +2502,7 @@
// Can't have a standalone document declaration of
"yes" if attribute
// values are subject to normalisation
fValidator->emitError(XMLValid::NoAttNormForStandalone, attrName);
+ ((SchemaAttDef
*)attDef)->setValidity(PSVIDefs::INVALID);
}
}
continue;
@@ -2414,6 +2517,9 @@
// And move up to the next character in the source
srcPtr++;
}
+
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->updateValidityFromAttribute((SchemaAttDef
*)attDef);
+
return retVal;
}
@@ -2657,6 +2763,7 @@
{
// They definitely cannot handle any type of char data
fValidator->emitError(XMLValid::NoCharDataInCM);
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
else if (fReaderMgr.getCurrentReader()->isAllSpaces(rawBuf, len))
{
@@ -2732,6 +2839,7 @@
else
{
fValidator->emitError(XMLValid::NoCharDataInCM);
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -3018,8 +3126,10 @@
{
const XMLCh* newUri =
root->getAttribute(SchemaSymbols::fgATT_TARGETNAMESPACE);
if (!XMLString::equals(newUri, uri)) {
- if (fValidate)
+ if (fValidate) {
fValidator->emitError(XMLValid::WrongTargetNamespace, loc,
uri);
+ }
+
grammar = fGrammarResolver->getGrammar(newUri);
}
@@ -3407,6 +3517,7 @@
// Error - standalone should have a value of "no" as whitespace
detected in an
// element type with element content whose element declaration
was external
fValidator->emitError(XMLValid::NoWSForStandalone);
+ ((SchemaElementDecl
*)(topElem->fThisElement))->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -3502,6 +3613,7 @@
{
// They definitely cannot handle any type of char data
fValidator->emitError(XMLValid::NoCharDataInCM);
+ ((SchemaElementDecl
*)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
@@ -3699,6 +3811,7 @@
// element type with element content whose element declaration
was external
//
fValidator->emitError(XMLValid::NoWSForStandalone);
+ ((SchemaElementDecl
*)fElemStack.topElement()->fThisElement)->setValidity(PSVIDefs::INVALID);
}
}
}
@@ -3936,6 +4049,7 @@
if (defType == XMLAttDef::ProcessContents_Skip) {
// attribute should just be bypassed,
skipThisOne = true;
+ attWildCard->setValidationAttempted(PSVIDefs::NONE);
}
else if (defType == XMLAttDef::ProcessContents_Lax) {
laxThisOne = true;
1.4 +4 -1 xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp
Index: SGXMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SGXMLScanner.hpp 15 Jan 2003 15:49:49 -0000 1.3
+++ SGXMLScanner.hpp 29 Jan 2003 19:59:35 -0000 1.4
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.4 2003/01/29 19:59:35 gareth
+ * we now detect when elements and attributes are validated/ the result of the
validation and store that information.
+ *
* Revision 1.3 2003/01/15 15:49:49 knoaman
* Change constant declaration name to match its value.
*
@@ -76,6 +79,7 @@
#include <xercesc/util/KVStringPair.hpp>
#include <xercesc/util/ValueHashTableOf.hpp>
#include <xercesc/validators/common/Grammar.hpp>
+#include <xercesc/validators/schema/SchemaElementDecl.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -306,7 +310,6 @@
{
return XMLUni::fgSGXMLScanner;
}
-
XERCES_CPP_NAMESPACE_END
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]