Exemplo n.º 1
0
        /// <summary>
        /// Only validation whether the children elements are valid according to this type's constraint defined in schema.
        /// </summary>
        /// <param name="validationContext">The validation context.</param>
        public static void Validate(ValidationContext validationContext)
        {
            Debug.Assert(validationContext != null);
            Debug.Assert(validationContext.Element != null);

            OpenXmlElement theElement = validationContext.Element;

            Debug.Assert(!(theElement is OpenXmlUnknownElement));
            Debug.Assert(!(theElement is OpenXmlMiscNode));

            if (theElement.IsReservedElement())
            {
                // MiscElement, UnknownElement,
                // AlternateContent, AlternateContentChoice, AlternateContentFallback
                if (theElement.IsAlternateContent())
                {
                    AlternateContentValidator.Validate(validationContext);
                }

                Debug.Assert(!(theElement is AlternateContentChoice));
                Debug.Assert(!(theElement is AlternateContentFallback));

                return;
            }

            // validate Ignorable, ProcessContent, etc. compatibility-rule attributes
            CompatibilityRuleAttributesValidator.ValidateMcAttributes(validationContext);

            ValidateAttributes(validationContext);

            // validate particles
            if (theElement is OpenXmlLeafTextElement)
            {
                SimpleContentComplexTypeValidator.Validate(validationContext);
            }
            else if (theElement is OpenXmlLeafElement)
            {
                EmptyComplexTypeValidator.Validate(validationContext);
            }
            else
            {
                Debug.Assert(theElement is OpenXmlCompositeElement);

                Debug.Assert(!(theElement is AlternateContentChoice));
                Debug.Assert(!(theElement is AlternateContentFallback));

                if (theElement.ParticleConstraint != null)
                {
                    // composite element
                    CompositeComplexTypeValidator.Validate(validationContext);
                }
                else
                {
                    // special case, see O14 bug #662644
                    // A root element which does not allow any children.
                    Debug.Assert(theElement is OpenXmlPartRootElement);
                    EmptyRootComplexTypeValidator.Validate(validationContext);
                }
            }
        }
Exemplo n.º 2
0
            internal static void Validate(ValidationContext validationContext, SimpleTypeRestriction simpleTypeConstraint)
            {
                // first check whether there are invalid children under this OpenXmlLeafTextElement.
                EmptyComplexTypeValidator.Validate(validationContext);

                OpenXmlLeafTextElement element = (OpenXmlLeafTextElement)validationContext.Element;
                OpenXmlSimpleType      value   = element.InnerTextToValue(element.Text);
                string qname = element.XmlQualifiedName.ToString();

                SchemaTypeValidator.ValidateValue(validationContext, simpleTypeConstraint, value, qname, false);
            }
Exemplo n.º 3
0
            internal static void Validate(ValidationContext validationContext)
            {
                // first check whether there are invalid children under this OpenXmlLeafTextElement.
                EmptyComplexTypeValidator.Validate(validationContext);

                var element = (OpenXmlLeafTextElement)validationContext.Element;
                var value   = element.InnerTextToValue(element.Text);
                var qname   = element.XmlQualifiedName.ToString();
                var state   = new ElementProperty <OpenXmlSimpleType>(element.NamespaceId, element.LocalName, 0, element.ElementData.Info.Validators, new ElementPropertyAccessor <OpenXmlSimpleType>(_ => value, (_, __) => throw new NotImplementedException(), value.GetType()));

                SchemaTypeValidator.ValidateValue(validationContext, element.ElementData.Info.Validators, value, qname, state, false);
            }
        /// <summary>
        /// Only validation whether the children elements are valid according to this type's constraint defined in schema.
        /// </summary>
        /// <param name="validationContext">The validation context.</param>
        internal void Validate(ValidationContext validationContext)
        {
            Debug.Assert(validationContext != null);
            Debug.Assert(validationContext.Element != null);

            OpenXmlElement theElement = validationContext.Element;

            Debug.Assert(!(theElement is OpenXmlUnknownElement));
            Debug.Assert(!(theElement is OpenXmlMiscNode));

            if (theElement.ElementTypeId < ReservedElementTypeIds.MaxReservedId)
            {
                // MiscElement, UnknownElement,
                // AlternateContent, AlternateContentChoice, AlternateContentFallback
                if (theElement.ElementTypeId == ReservedElementTypeIds.AlternateContentId)
                {
                    AlternateContentValidator.Validate(validationContext);
                }

                Debug.Assert(!(theElement is AlternateContentChoice));
                Debug.Assert(!(theElement is AlternateContentFallback));

                return;
            }

            // validte Inorable, ProcessContent, etc. compatibility-rule attributes
            CompatibilityRuleAttributesValidator.ValidateMcAttributes(validationContext);

            SchemaTypeData schemaTypeData = this._sdbSchemaDatas.GetSchemaTypeData(theElement);

            ValidateAttributes(validationContext, schemaTypeData);

            // validate particles

            if (theElement is OpenXmlLeafTextElement)
            {
                SimpleContentComplexTypeValidator.Validate(validationContext, schemaTypeData.SimpleTypeConstraint);
            }
            else if (theElement is OpenXmlLeafElement)
            {
                EmptyComplexTypeValidator.Validate(validationContext);
            }
            else
            {
                Debug.Assert(theElement is OpenXmlCompositeElement);

                Debug.Assert(!(theElement is AlternateContentChoice));
                Debug.Assert(!(theElement is AlternateContentFallback));

                if (schemaTypeData.ParticleConstraint != null)
                {
                    // composite element
                    CompositeComplexTypeValidator.Validate(validationContext, schemaTypeData.ParticleConstraint);
                }
                else
                {
                    // special case, see O14 bug #662644
                    // A root element which does not allow any children.
                    Debug.Assert(theElement is OpenXmlPartRootElement);
                    EmptyRootComplexTypeValidator.Validate(validationContext);
                }
            }
        }