System.Xml.XmlDocument.Validate C# (CSharp) Method

Validate() public method

public Validate ( ValidationEventHandler validationEventHandler, XmlNode nodeToValidate ) : void
validationEventHandler ValidationEventHandler
nodeToValidate XmlNode
return void
        public void Validate(ValidationEventHandler validationEventHandler, XmlNode nodeToValidate)
        {
            if (_schemas == null || _schemas.Count == 0)
            { //Should we error
                throw new InvalidOperationException(SR.XmlDocument_NoSchemaInfo);
            }
            XmlDocument parentDocument = nodeToValidate.Document;
            if (parentDocument != this)
            {
                throw new ArgumentException(SR.Format(SR.XmlDocument_NodeNotFromDocument, nameof(nodeToValidate)));
            }
            if (nodeToValidate == this)
            {
                _reportValidity = false;
            }
            DocumentSchemaValidator validator = new DocumentSchemaValidator(this, _schemas, validationEventHandler);
            validator.Validate(nodeToValidate);
            if (nodeToValidate == this)
            {
                _reportValidity = true;
            }
        }

Same methods

XmlDocument::Validate ( ValidationEventHandler validationEventHandler ) : void

Usage Example

        internal static void Main()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("../../../correctXML.xml");
            doc.Schemas.Add("urn:catalogueSchema", "../../../catalogueSchema.xsd");

            ValidationEventHandler eventhandler = new ValidationEventHandler(ValidateEventHandler);
            doc.Validate(eventhandler);

            // I Just delete albums element.
            doc.Load("../../../invalidXML.xml");
            doc.Validate(eventhandler);
        }
All Usage Examples Of System.Xml.XmlDocument::Validate