You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/11/13 14:27:29 UTC
cvs commit: xml-xerces/c/src/validators/DTD DTDScanner.cpp
tng 01/11/13 05:27:29
Modified: c/src/internal XMLScanner.cpp XMLScanner.hpp XMLScanner2.cpp
c/src/validators/DTD DTDScanner.cpp
Log:
Move root element check to XMLScanner.
Revision Changes Path
1.73 +32 -11 xml-xerces/c/src/internal/XMLScanner.cpp
Index: XMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.cpp,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- XMLScanner.cpp 2001/11/02 14:20:14 1.72
+++ XMLScanner.cpp 2001/11/13 13:27:28 1.73
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner.cpp,v 1.72 2001/11/02 14:20:14 knoaman Exp $
+ * $Id: XMLScanner.cpp,v 1.73 2001/11/13 13:27:28 tng Exp $
*/
@@ -215,6 +215,7 @@
, fMatcherStack(0)
, fValueStoreCache(0)
, fFieldActivator(0)
+ , fRootElemName(0)
{
commonInit();
@@ -276,6 +277,7 @@
, fMatcherStack(0)
, fValueStoreCache(0)
, fFieldActivator(0)
+ , fRootElemName(0)
{
commonInit();
@@ -311,6 +313,8 @@
delete fFieldActivator;
delete fMatcherStack;
delete fValueStoreCache;
+
+ delete [] fRootElemName;
}
@@ -944,7 +948,7 @@
initValidator(fSchemaValidator);
// Create IdentityConstraint info
- fMatcherStack = new XPathMatcherStack();
+ fMatcherStack = new XPathMatcherStack();
fValueStoreCache = new ValueStoreCache();
fFieldActivator = new FieldActivator(fValueStoreCache, fMatcherStack);
fValueStoreCache->setScanner(this);
@@ -2138,9 +2142,18 @@
//
// We have a doc type. So, create a DTDScanner and
- // store the Grammar in DTDGrammar.
+ // switch the Grammar to the emptyNamespace one.
//
+ if (!switchGrammar(XMLUni::fgZeroLenString) && fValidate)
+ {
+ fValidator->emitError
+ (
+ XMLValid::GrammarNotFound
+ , XMLUni::fgZeroLenString
+ );
+ }
+
DTDScanner fDTDScanner((DTDGrammar*)fGrammar, fEntityDeclPool, fDocTypeHandler);
fDTDScanner.setScannerInfo(this, &fReaderMgr, &fBufMgr);
fDTDScanner.scanDocTypeDecl(fReuseGrammar);
@@ -2299,15 +2312,19 @@
//
// If this is the first element and we are validating, check the root
- // element. This may or may not have any meaning for the installed
- // validator, in which case it may just always return success. Some
- // validators will treat any element as the root.
+ // element.
//
if (isRoot)
{
if (fValidate)
{
- if (!fValidator->checkRootElement(elemDecl->getId()))
+ // If a DocType exists, then check if it matches the root name there.
+ if (fRootElemName && XMLString::compareString(fQNameBuf.getRawBuffer(), fRootElemName))
+ fValidator->emitError(XMLValid::RootElemNotLikeDocType);
+
+ // Some validators may also want to check the root, call the
+ // XMLValidator::checkRootElement
+ if (fValidatorFromUser && !fValidator->checkRootElement(elemDecl->getId()))
fValidator->emitError(XMLValid::RootElemNotLikeDocType);
}
}
@@ -3218,15 +3235,19 @@
//
// If this is the first element and we are validating, check the root
- // element. This may or may not have any meaning for the installed
- // validator, in which case it may just always return success. Some
- // validators will treat any element as the root.
+ // element.
//
if (isRoot)
{
if (fValidate)
{
- if (!fValidator->checkRootElement(elemDecl->getId()))
+ // If a DocType exists, then check if it matches the root name there.
+ if (fRootElemName && XMLString::compareString(qnameRawBuf, fRootElemName))
+ fValidator->emitError(XMLValid::RootElemNotLikeDocType);
+
+ // Some validators may also want to check the root, call the
+ // XMLValidator::checkRootElement
+ if (fValidatorFromUser && !fValidator->checkRootElement(elemDecl->getId()))
fValidator->emitError(XMLValid::RootElemNotLikeDocType);
}
}
1.36 +17 -0 xml-xerces/c/src/internal/XMLScanner.hpp
Index: XMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.hpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- XMLScanner.hpp 2001/11/02 14:20:14 1.35
+++ XMLScanner.hpp 2001/11/13 13:27:28 1.36
@@ -56,6 +56,9 @@
/*
* $Log: XMLScanner.hpp,v $
+ * Revision 1.36 2001/11/13 13:27:28 tng
+ * Move root element check to XMLScanner.
+ *
* Revision 1.35 2001/11/02 14:20:14 knoaman
* Add support for identity constraints.
*
@@ -461,6 +464,7 @@
void setDoSchema(const bool doSchema);
void setValidationSchemaFullChecking(const bool schemaFullChecking);
void setHasNoDTD(const bool hasNoDTD);
+ void setRootElemName(XMLCh* rootElemName);
// -----------------------------------------------------------------------
// Mutator methods
@@ -859,6 +863,12 @@
// fFieldActivator
// Activates fields within a certain scope when a selector matches
// its xpath.
+ //
+ // fRootElemName
+ // No matter we are using DTD or Schema Grammar, if a DOCTYPE exists,
+ // we need to verify the root element name. So store the rootElement
+ // that is used in the DOCTYPE in the Scanner instead of in the DTDGrammar
+ // where it used to
// -----------------------------------------------------------------------
bool fDoNamespaces;
bool fExitOnFirstFatal;
@@ -913,6 +923,7 @@
XPathMatcherStack* fMatcherStack;
ValueStoreCache* fValueStoreCache;
FieldActivator* fFieldActivator;
+ XMLCh* fRootElemName;
};
@@ -1192,6 +1203,12 @@
inline void XMLScanner::setHasNoDTD(const bool hasNoDTD)
{
fHasNoDTD = hasNoDTD;
+}
+
+inline void XMLScanner::setRootElemName(XMLCh* rootElemName)
+{
+ delete [] fRootElemName;
+ fRootElemName = XMLString::replicate(rootElemName);
}
// ---------------------------------------------------------------------------
1.65 +5 -1 xml-xerces/c/src/internal/XMLScanner2.cpp
Index: XMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner2.cpp,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- XMLScanner2.cpp 2001/11/02 20:54:04 1.64
+++ XMLScanner2.cpp 2001/11/13 13:27:28 1.65
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner2.cpp,v 1.64 2001/11/02 20:54:04 knoaman Exp $
+ * $Id: XMLScanner2.cpp,v 1.65 2001/11/13 13:27:28 tng Exp $
*/
@@ -1010,6 +1010,10 @@
// Clear out the id reference list
fIDRefList->removeAll();
+
+ // Reset the Root Element Name
+ delete [] fRootElemName;
+ fRootElemName = 0;
// Reset IdentityConstraints
fMatcherStack->clear();
1.21 +27 -11 xml-xerces/c/src/validators/DTD/DTDScanner.cpp
Index: DTDScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/DTD/DTDScanner.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DTDScanner.cpp 2001/09/05 20:49:10 1.20
+++ DTDScanner.cpp 2001/11/13 13:27:28 1.21
@@ -56,6 +56,9 @@
/*
* $Log: DTDScanner.cpp,v $
+ * Revision 1.21 2001/11/13 13:27:28 tng
+ * Move root element check to XMLScanner.
+ *
* Revision 1.20 2001/09/05 20:49:10 knoaman
* Fix for complexTypes with mixed content model.
*
@@ -1608,8 +1611,13 @@
}
//
+ // Store the root element name for later check
+ //
+ fScanner->setRootElemName(bbRootName.getRawBuffer());
+
+ //
// This element obviously is not going to exist in the element decl
- // pool yet, but we need to store away an element id. So force it into
+ // pool yet, but we need to call docTypeDecl. So force it into
// the element decl pool, marked as being there because it was in
// the DOCTYPE. Later, when its declared, the status will be updated.
//
@@ -1617,20 +1625,28 @@
// then look it up instead. It has to exist!
//
DTDElementDecl* rootDecl;
+ Janitor<DTDElementDecl> janSrc(0);
+
if (reuseGrammar)
{
- rootDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
- if (fScanner->getDoValidation())
- {
- if (!rootDecl)
- {
- fScanner->getValidator()->emitError(XMLValid::UndeclaredElemInDocType, bbRootName.getRawBuffer());
- fReaderMgr->skipPastChar(chCloseAngle);
- return;
+ Grammar* fGrammar = fDTDGrammar;
+ if (fGrammar->getGrammarType() == Grammar::DTDGrammarType) {
+ rootDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
+ if (rootDecl)
+ fDTDGrammar->setRootElemId(rootDecl->getId());
+ else {
+ rootDecl = new DTDElementDecl(bbRootName.getRawBuffer(), fEmptyNamespaceId);
+ rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
+ rootDecl->setExternalElemDeclaration(isReadingExternalEntity());
+ fDTDGrammar->setRootElemId(fDTDGrammar->putElemDecl(rootDecl));
}
+ }
+ else {
+ rootDecl = new DTDElementDecl(bbRootName.getRawBuffer(), fEmptyNamespaceId);
+ rootDecl->setCreateReason(DTDElementDecl::AsRootElem);
+ rootDecl->setExternalElemDeclaration(isReadingExternalEntity());
+ janSrc.reset(rootDecl);
}
- if (rootDecl)
- fDTDGrammar->setRootElemId(rootDecl->getId());
}
else
{
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org