//============================================================================== // ElementType::validateMissingAttributes // // Test if all required attributes have been specified and add attributes // that have a default value // //============================================================================== void ElementType::validateMissingAttributes(AttributeSet& attSet, bool bValidate, ParserImpl& parser) const { AttributeTypeMap::const_iterator iter; for(iter=m_attributeTypeMap.begin(); iter!=m_attributeTypeMap.end(); ++iter) { const AutoPtr<AttributeType>& rpAttrType = (*iter).second; if(rpAttrType->getDefaultType() == AttributeType::REQUIRED) { if(bValidate && !attSet.getAttribute(rpAttrType->getName().getRawName())) { const String& errMsg = MessageFormatter::Format( System::GetSysMessage(sXML, EXML_ATTRREQUIRED, "required attribute '{0}' has not been supplied for element '{1}'"), rpAttrType->getName().getRawName(), getName().getRawName()); parser.errorDetected(Parser::Error, errMsg, EXML_ATTRREQUIRED); } } else if(rpAttrType->getDefaultType() != AttributeType::IMPLIED) { // XML 1.0 says that attributes with default value // that are not present should be created if(!attSet.getAttribute(rpAttrType->getName().getRawName())) { AutoPtr<Attribute> rpAttr = new Attribute(rpAttrType->getName(), rpAttrType->getDefaultValue(), rpAttrType->getTypeAsString()); attSet.addAttribute(rpAttr.get()); // // If we have had to add a defaulted attribute, and if the attribute // definition is external, and the document claims to be standalone // then we have a vandity constraint error // if(bValidate && parser.isStandaloneDocument() && rpAttrType->isExternallyDeclared()) { const String& errMsg = MessageFormatter::Format( System::GetSysMessage(sXML, EXML_ATTRDEFAULTNOTSA, "externally declared attribute '{0}' for element '{1}' has a default value of '{2}' which must be specified in a standalone document"), rpAttrType->getName().getRawName(), getName().getRawName(), rpAttrType->getDefaultValue()); parser.errorDetected(Parser::Error, errMsg, EXML_ATTRDEFAULTNOTSA); } } } } }
//============================================================================== // ElementType::validate // // Perform post DTD validation, i.e. validation checks that must be performed // when the entire DTD has been processed. //============================================================================== void ElementType::validate(ParserImpl& parser) const { AttributeTypeMap::const_iterator iter; for(iter=m_attributeTypeMap.begin(); iter!=m_attributeTypeMap.end(); ++iter) { const AutoPtr<AttributeType>& rpAttr = (*iter).second; rpAttr->validate(parser); } // // A couple of warning/compatability checks follow // if(parser.m_features.m_bDoWarningChecks) { if(m_eContentType == EMPTY && hasNotationAttribute()) { // Validity Constraint: (For compatability) No Notation on Empty Element const String& errMsg = MessageFormatter::Format( System::GetSysMessage(sXML, EXML_EMPTYELEMNOTN, "attribute '{0}' of type NOTATION must not be declared on element '{1}' which has been declared EMPTY"), getNotationAttributeName(), m_name.getRawName()); parser.errorDetected(Parser::Error, errMsg, EXML_EMPTYELEMNOTN); } // XML 1.0, 3.3 says we can (at user option) issue a warning // if the element has not been declared if(!m_bDefined) { const String& errMsg = MessageFormatter::Format( System::GetSysMessage(sXML, EXML_ELEMUNDEFATTLIST, "attribute list declared for undefined element '{0}'"), m_name.getRawName()); parser.errorDetected(Parser::Warning, errMsg, EXML_ELEMUNDEFATTLIST); } } }