예제 #1
0
        /// <summary>
        /// After the body state - nothing except Comment PI S allowed.
        /// </summary>
        /// <param name="token">The consumed token.</param>
        void AfterBody(XmlToken token)
        {
            switch (token.Type)
            {
            case XmlTokenType.ProcessingInstruction:
            case XmlTokenType.Comment:
            {
                InMisc(token);
                break;
            }

            case XmlTokenType.EOF:
            {
                if (doc.Options.IsValidating && !XmlValidator.Run(doc))
                {
                    throw Errors.Xml(ErrorCode.XmlValidationFailed);
                }

                break;
            }

            default:
            {
                if (!token.IsIgnorable)
                {
                    throw Errors.Xml(ErrorCode.XmlMissingRoot);
                }

                break;
            }
            }
        }
예제 #2
0
        /// <summary>
        /// Runs the Validation with the given document.
        /// </summary>
        /// <param name="doc">The document to inspect.</param>
        /// <returns>True if the validation has been successful, otherwise false.</returns>
        public static Boolean Run(XMLDocument doc)
        {
            if (doc.Doctype == null || doc.Doctype.TypeDefinitions == null)
                return false;

            var validator = new XmlValidator();
            validator.Definition = doc.Doctype.TypeDefinitions;

            if (!validator.Definition.IsInvalid && doc.DocumentElement.NodeName == doc.Doctype.Name)
                return validator.Inspect(doc.DocumentElement);

            return false;
        }
예제 #3
0
        /// <summary>
        /// Runs the Validation with the given document.
        /// </summary>
        /// <param name="doc">The document to inspect.</param>
        /// <returns>True if the validation has been successful, otherwise false.</returns>
        public static Boolean Run(XMLDocument doc)
        {
            if (doc.Doctype == null || doc.Doctype.TypeDefinitions == null)
            {
                return(false);
            }

            var validator = new XmlValidator();

            validator.Definition = doc.Doctype.TypeDefinitions;

            if (!validator.Definition.IsInvalid && doc.DocumentElement.NodeName == doc.Doctype.Name)
            {
                return(validator.Inspect(doc.DocumentElement));
            }

            return(false);
        }