XmlSchemaCollection XmlSchemaCollection XmlSchemaCollection XmlSchemaCollection Class

Definition

Warning

This API is now obsolete.

Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. The XmlSchemaCollection class class is obsolete. Use XmlSchemaSet instead.

public ref class XmlSchemaCollection sealed : System::Collections::ICollection
[System.Obsolete("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202")]
public sealed class XmlSchemaCollection : System.Collections.ICollection
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class XmlSchemaCollection
Implements ICollection
Inheritance
XmlSchemaCollectionXmlSchemaCollectionXmlSchemaCollectionXmlSchemaCollection
Attributes
Implements

Examples

The following example validates an XML document using the XmlSchemaCollection.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;
public ref class ValidXSD
{
public:
   static void main()
   {
      XmlSchemaCollection^ sc = gcnew XmlSchemaCollection;
      sc->ValidationEventHandler += gcnew ValidationEventHandler( ValidationCallBack );
      sc->Add( nullptr, "books.xsd" );
      if ( sc->Count > 0 )
      {
         XmlTextReader^ tr = gcnew XmlTextReader( "notValidXSD.xml" );
         XmlValidatingReader^ rdr = gcnew XmlValidatingReader( tr );
         rdr->ValidationType = ValidationType::Schema;
         rdr->Schemas->Add( sc );
         rdr->ValidationEventHandler += gcnew ValidationEventHandler( ValidationCallBack );
         while ( rdr->Read() )
                  ;
      }
   }


private:
   static void ValidationCallBack( Object^ /*sender*/, ValidationEventArgs^ e )
   {
      Console::WriteLine( "Validation Error: {0}", e->Message );
   }

};

int main()
{
   ValidXSD::main();
}

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

public class ValidXSD {

  public static void Main() {
    XmlSchemaCollection sc = new XmlSchemaCollection();
    sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
    sc.Add(null, "books.xsd");

    if(sc.Count > 0)
    {
      XmlTextReader tr = new XmlTextReader("notValidXSD.xml");
      XmlValidatingReader rdr = new XmlValidatingReader(tr);

      rdr.ValidationType = ValidationType.Schema;
      rdr.Schemas.Add(sc);
      rdr.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
      while (rdr.Read());
    }
    
  }

  private static void ValidationCallBack(object sender, ValidationEventArgs e) {
    Console.WriteLine("Validation Error: {0}", e.Message);
  }
}
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO

public class ValidXSD 

  public shared sub Main() 
    Dim sc as XmlSchemaCollection = new XmlSchemaCollection()
    AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack
    sc.Add(nothing, "books.xsd")

    if(sc.Count > 0)
      Dim tr as XmlTextReader = new XmlTextReader("notValidXSD.xml")
      Dim rdr as XmlValidatingReader = new XmlValidatingReader(tr)

      rdr.ValidationType = ValidationType.Schema
      rdr.Schemas.Add(sc)
      AddHandler rdr.ValidationEventHandler, AddressOf ValidationCallBack
      while (rdr.Read())
      end while
    end if

  end sub

  private shared sub ValidationCallBack(sender as object, e as ValidationEventArgs) 
    Console.WriteLine("XSD Error: {0}", e.Message)
  end sub

end class

Remarks

Schemas are loaded using the Add method, at which time the schema is associated with a namespace Uniform Resource Identifier (URI). For XML Schemas, this will typically be the targetNamespace property of the schema.

Although this class stores both XML Schemas and XDR schemas, any method and property that takes or returns an XmlSchema applies to XML Schemas only.

This version of the product supports the World Wide Web Consortium (W3C) XML Schema recommendation located at http://www.w3.org/TR/xmlschema-1 and http://www.w3.org/TR/xmlschema-2. An XML Schema must reference the W3C Schema namespace http://www.w3.org/2001/XMLSchema in its schema element. See the Add method for an example.

XmlSchemaCollection can be used by XmlValidatingReader for efficient data validation.

Important

The XmlSchemaCollection class is obsolete in the Microsoft .NET Framework version 2.0 and has been replaced by the XmlSchemaSet class.

Constructors

XmlSchemaCollection() XmlSchemaCollection() XmlSchemaCollection() XmlSchemaCollection()

Initializes a new instance of the XmlSchemaCollection class.

XmlSchemaCollection(XmlNameTable) XmlSchemaCollection(XmlNameTable) XmlSchemaCollection(XmlNameTable) XmlSchemaCollection(XmlNameTable)

Initializes a new instance of the XmlSchemaCollection class with the specified XmlNameTable. The XmlNameTable is used when loading schemas.

Properties

Count Count Count Count

Gets the number of namespaces defined in this collection.

Item[String] Item[String] Item[String] Item[String]

Gets the XmlSchema associated with the given namespace URI.

NameTable NameTable NameTable NameTable

Gets the default XmlNameTable used by the XmlSchemaCollection when loading new schemas.

Methods

Add(String, String) Add(String, String) Add(String, String) Add(String, String)

Adds the schema located by the given URL into the schema collection.

Add(String, XmlReader) Add(String, XmlReader) Add(String, XmlReader) Add(String, XmlReader)

Adds the schema contained in the XmlReader to the schema collection.

Add(String, XmlReader, XmlResolver) Add(String, XmlReader, XmlResolver) Add(String, XmlReader, XmlResolver) Add(String, XmlReader, XmlResolver)

Adds the schema contained in the XmlReader to the schema collection. The specified XmlResolver is used to resolve any external resources.

Add(XmlSchema) Add(XmlSchema) Add(XmlSchema) Add(XmlSchema)

Adds the XmlSchema to the collection.

Add(XmlSchema, XmlResolver) Add(XmlSchema, XmlResolver) Add(XmlSchema, XmlResolver) Add(XmlSchema, XmlResolver)

Adds the XmlSchema to the collection. The specified XmlResolver is used to resolve any external references.

Add(XmlSchemaCollection) Add(XmlSchemaCollection) Add(XmlSchemaCollection) Add(XmlSchemaCollection)

Adds all the namespaces defined in the given collection (including their associated schemas) to this collection.

Contains(String) Contains(String) Contains(String) Contains(String)

Gets a value indicating whether a schema with the specified namespace is in the collection.

Contains(XmlSchema) Contains(XmlSchema) Contains(XmlSchema) Contains(XmlSchema)

Gets a value indicating whether the targetNamespace of the specified XmlSchema is in the collection.

CopyTo(XmlSchema[], Int32) CopyTo(XmlSchema[], Int32) CopyTo(XmlSchema[], Int32) CopyTo(XmlSchema[], Int32)

Copies all the XmlSchema objects from this collection into the given array starting at the given index.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Provides support for the "for each" style iteration over the collection of schemas.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Events

ValidationEventHandler ValidationEventHandler ValidationEventHandler ValidationEventHandler

Sets an event handler for receiving information about the XDR and XML schema validation errors.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

For a description of this member, see CopyTo(XmlSchema[], Int32).

ICollection.Count ICollection.Count ICollection.Count ICollection.Count

For a description of this member, see Count.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

For a description of this member, see ICollection.IsSynchronized.

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

For a description of this member, see ICollection.SyncRoot.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

For a description of this member, see GetEnumerator().

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to