XmlSchemaIntegrityValidationWarning Class
The XmlSchemaIntegrityValidationWarning class represents a warning generated during integrity validation of an XML schema. It provides details about the warning, including a message, line number, and the location within the source file.
Namespace
System.Xml
Assembly
System.Xml.dll
Inheritance
Object → XmlSchemaIntegrityValidationWarning
Constructors
| Signature | Description |
|---|---|
XmlSchemaIntegrityValidationWarning(string message) | Initializes a new instance with a warning message. |
XmlSchemaIntegrityValidationWarning(string message, int lineNumber, int linePosition) | Initializes a new instance with a message and location information. |
Properties
| Name | Type | Description |
|---|---|---|
Message | String | The warning description. |
LineNumber | Int32 | The line number where the warning occurred. |
LinePosition | Int32 | The position within the line where the warning occurred. |
SourceUri | String | The URI of the source XML schema. |
Methods
ToString()– Returns a string representation of the warning.
Example
using System;
using System.Xml;
using System.Xml.Schema;
class Program
{
static void Main()
{
var settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += OnValidation;
using (XmlReader reader = XmlReader.Create("example.xsd", settings))
{
while (reader.Read()) { }
}
}
static void OnValidation(object sender, ValidationEventArgs e)
{
if (e.Severity == XmlSeverityType.Warning)
{
var warning = new XmlSchemaIntegrityValidationWarning(e.Message,
((XmlSchemaException)e.Exception).LineNumber,
((XmlSchemaException)e.Exception).LinePosition);
Console.WriteLine(warning);
}
}
}