MSDN Documentation

XMLSchemaIntegrityValidationWarning Class

The XMLSchemaIntegrityValidationWarning class represents a warning that occurs during XML Schema validation but does not cause the validation to fail. It provides details about the warning, including the message, line number, and source URI.

Namespace

System.Xml.Schema

Assembly

System.Xml.dll

Syntax

public sealed class XMLSchemaIntegrityValidationWarning : System.Xml.Schema.XmlSchemaException

Members

MemberDescription
MessageGets a message that describes the warning.
SourceUriGets the URI of the source document where the warning occurred.
LineNumberGets the line number where the warning was detected.
LinePositionGets the line position within the line where the warning was detected.
SeverityGets the severity level of the warning (always Warning).

Example

The following example demonstrates how to catch XMLSchemaIntegrityValidationWarning objects during schema validation.

using System;
using System.Xml;
using System.Xml.Schema;

class Program
{
    static void Main()
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.Schemas.Add(null, "example.xsd");
        settings.ValidationType = ValidationType.Schema;
        settings.ValidationEventHandler += ValidationCallback;

        using (XmlReader reader = XmlReader.Create("example.xml", settings))
        {
            while (reader.Read()) { }
        }
    }

    static void ValidationCallback(object sender, ValidationEventArgs e)
    {
        if (e.Exception is XMLSchemaIntegrityValidationWarning warning)
        {
            Console.WriteLine($\"Warning: {warning.Message}\");
            Console.WriteLine($\"Location: {warning.SourceUri} (Line {warning.LineNumber}, Position {warning.LinePosition})\");
        }
        else
        {
            Console.WriteLine($\"Error: {e.Message}\");
        }
    }
}

See Also