Example #1
0
        public void Validate(ValidationContext validationContext)
        {
            Debug.Assert(validationContext is not null);
            Debug.Assert(validationContext.Stack.Current.Element is not null);

            var openxmlElement = validationContext.Stack.Current.Element;

            Debug.Assert(!(openxmlElement is OpenXmlUnknownElement || openxmlElement is OpenXmlMiscNode));

            // Can not just validate AlternateContent / Choice / Fallback
            // Debug.Assert(!(openxmlElement is AlternateContent))
            Debug.Assert(!(openxmlElement is AlternateContentChoice || openxmlElement is AlternateContentFallback));

            ValidationTraverser.ValidatingTraverse(validationContext, SchemaTypeValidator.Validate);

            ValidationTraverser.ValidatingTraverse(validationContext, context =>
            {
                foreach (var constraint in context.Stack.Current.Element.Metadata.Constraints)
                {
                    constraint.Validate(context);
                }
            });
        }
Example #2
0
        public void Validate(ValidationContext validationContext)
        {
            var openxmlElement = validationContext.Stack.Current?.Element;

            if (openxmlElement is null)
            {
                return;
            }

            if (openxmlElement is OpenXmlUnknownElement || openxmlElement is OpenXmlMiscNode)
            {
                return;
            }

            // Can not just validate AlternateContent / Choice / Fallback
            if (openxmlElement is AlternateContentChoice || openxmlElement is AlternateContentFallback || openxmlElement is AlternateContentChoice)
            {
                return;
            }

            ValidationTraverser.ValidatingTraverse(validationContext, SchemaTypeValidator.Validate);

            ValidationTraverser.ValidatingTraverse(validationContext, context =>
            {
                var element = context.Stack.Current?.Element;

                if (element is null)
                {
                    return;
                }

                foreach (var constraint in element.Metadata.Constraints)
                {
                    constraint.Validate(context);
                }
            });
        }