System.Xml.Schema.ValidationEventArgs Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Returns detailed information related to the ValidationEventHandler.
C# Syntax:
public sealed class ValidationEventArgs : EventArgs
Example
For an example, see the add (string string) method for the XmlSchemaCollection class.
See also:
System.Xml.Schema Namespace

System.Xml.Schema.ValidationEventArgs Member List:

Public Properties
Exception Read-only

Message Read-only

Gets the text description corresponding to the validation event.
Severity Read-only

Gets the severity of the validation event.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Schema.ValidationEventArgs Member Details

Property: Exception (read-only)
Summary
Gets the XmlSchemaException associated with the validation event.
C# Syntax:
public XmlSchemaException Exception {get;}

Return to top


Property: Message (read-only)
Summary
Gets the text description corresponding to the validation event.
C# Syntax:
public string Message {get;}

Return to top


Property: Severity (read-only)
Summary
Gets the severity of the validation event.
C# Syntax:
public XmlSeverityType Severity {get;}
Example
The following example validates an XML file and generates the appropriate error or warning.
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Sample
{

  public static void Main ()
  {
    //Load the schema collection.
    XmlSchemaCollection xsc = new XmlSchemaCollection();
    xsc.Add("urn:bookstore-schema", "books.xsd");

    //Validate the file using the schema stored in the collection.
    //Any elements belonging to the namespace "urn:cd-schema" generate
    //a warning since the there is no schema matching that namespace.
    Validate("store.xml", xsc); 
  }

  private static void Validate(String filename, XmlSchemaCollection xsc)
  {
     Console.WriteLine();
     Console.WriteLine("\r\nValidating XML file {0}...", filename.ToString());
     XmlTextReader reader = new XmlTextReader (filename);
     XmlValidatingReader vreader=new XmlValidatingReader (reader);
     vreader.ValidationType = ValidationType.Schema;
     vreader.Schemas.Add(xsc);

     //Set the validation event handler.
     vreader.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
     //Read the XML data.
     while (vreader.Read()){}

     //Close the reader.
     vreader.Close();
  } 

  //Display any warnings or errors.
  public static void ValidationCallBack (object sender, ValidationEventArgs args)
  {
     if (args.Severity==XmlSeverityType.Warning)
       Console.WriteLine("\tWarning: Matching schema not found.  No validation occurred." + args.Message);
     else
        Console.WriteLine("\tValidation error: " + args.Message);

  }  
}

    

The preceding example uses the following input files.

store.xml

<?xml version='1.0'?>
<bookstore xmlns="urn:bookstore-schema" xmlns:cd="urn:cd-schema">
  <book genre="novel">
    <title>The Confidence Man</title>
    <price>11.99</price>
  </book>
  <cd:cd>
    <title>Americana</title>
    <cd:artist>Offspring</cd:artist>
    <price>16.95</price>
  </cd:cd>
</bookstore>

    
books.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="urn:bookstore-schema"
    elementFormDefault="qualified"
    targetNamespace="urn:bookstore-schema">

 <xsd:element name="bookstore" type="bookstoreType"/>

 <xsd:complexType name="bookstoreType">
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="book"  type="bookType"/>
  </xsd:sequence>
 </xsd:complexType>

 <xsd:complexType name="bookType">
  <xsd:sequence>
   <xsd:element name="title" type="xsd:string"/>
   <xsd:element name="author" type="authorName"/>
   <xsd:element name="price"  type="xsd:decimal"/>
  </xsd:sequence>
  <xsd:attribute name="genre" type="xsd:string"/>
 </xsd:complexType>

 <xsd:complexType name="authorName">
  <xsd:sequence>
   <xsd:element name="first-name"  type="xsd:string"/>
   <xsd:element name="last-name" type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>

</xsd:schema>

    

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~ValidationEventArgs();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.