XmlSchemaCollection Class
TOC
Collapse the table of content
Expand the table of content

XmlSchemaCollection Class

NOTE: This API is now obsolete.

Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. This class cannot be inherited.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

[ObsoleteAttribute(L"Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202")]
public ref class XmlSchemaCollection sealed : ICollection, 
	IEnumerable

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 noteImportant Note:

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

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 <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;

public __gc class ValidXSD {
public:
  static void main() {
    XmlSchemaCollection* sc = new XmlSchemaCollection();
    sc->ValidationEventHandler += new ValidationEventHandler(0, ValidationCallBack);
    sc->Add(0, S"books.xsd");

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

      rdr->ValidationType = ValidationType::Schema;
      rdr->Schemas->Add(sc);
      rdr->ValidationEventHandler += new ValidationEventHandler(0, ValidationCallBack);
      while (rdr->Read());
    }

  }

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

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

System::Object
  System.Xml.Schema::XmlSchemaCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

Community Additions

ADD
Show:
© 2016 Microsoft