.NET API Reference

XmlSchemaIntegrityValidationWarningSummary Class

Namespace: System.Xml

Assembly: System.Xml.dll

Inheritance: Object > CompilerResults > XmlSchemaIntegrityValidationWarningSummary

Represents a summary of warnings encountered during XML schema integrity validation. This class is used to report issues found in an XML schema, such as invalid elements, attributes, or type definitions, without necessarily causing the validation to fail entirely.

Constructors

public XmlSchemaIntegrityValidationWarningSummary()

Initializes a new instance of the XmlSchemaIntegrityValidationWarningSummary class.

Properties

Name Type Description
Errors IList Gets a list of errors that occurred during schema validation. While named 'Errors', this list may contain warnings as well, depending on the context of the validation.
HasErrors Boolean Gets a value indicating whether the schema validation encountered any errors or warnings.
Errors.Count Int32 Gets the number of errors and warnings reported.

Methods

public void AddWarning(string message)

Adds a new warning message to the summary.

Parameter Type Description
message String The warning message to add.
public void AddError(string message)

Adds a new error message to the summary. This is typically used when a validation issue is critical and should be treated as an error.

Parameter Type Description
message String The error message to add.

Remarks

The XmlSchemaIntegrityValidationWarningSummary class is particularly useful in scenarios where you need to perform a comprehensive validation of an XML schema, but also want to report any deviations or potential issues without halting the process. It allows developers to gather detailed feedback on schema quality.

Example


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

// Assume schema and xmlDoc are already loaded and validated
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("http://www.example.com/schema", "path/to/your/schema.xsd");

XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = schemaSet;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;

XmlSchemaIntegrityValidationWarningSummary warnings = new XmlSchemaIntegrityValidationWarningSummary();

settings.ValidationEventHandler += (sender, e) =>
{
    if (e.Severity == XmlSeverityType.Warning)
    {
        warnings.AddWarning($"Schema Warning: {e.Message} at line {e.Exception.LineNumber}, position {e.Exception.LinePosition}");
    }
    else if (e.Severity == XmlSeverityType.Error)
    {
        warnings.AddError($"Schema Error: {e.Message} at line {e.Exception.LineNumber}, position {e.Exception.LinePosition}");
    }
};

// Use a validating reader to process an XML document
using (XmlReader reader = XmlReader.Create("path/to/your/document.xml", settings))
{
    while (reader.Read()) { }
}

if (warnings.HasErrors)
{
    Console.WriteLine("Validation completed with issues:");
    foreach (var error in warnings.Errors)
    {
        Console.WriteLine(error);
    }
}
else
{
    Console.WriteLine("Schema validation successful with no reported issues.");
}