Freigeben über


XmlSchemaCollection-Klasse

HINWEIS: Diese Klasse ist mittlerweile veraltet.

Enthält einen Cache mit XSD-Schemas (XML Schema Definition) und XDR-Schemas (XML-Data Reduced). Diese Klasse kann nicht vererbt werden.

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

Syntax

'Declaration
<ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202")> _
Public NotInheritable Class XmlSchemaCollection
    Implements ICollection, IEnumerable
'Usage
Dim instance As XmlSchemaCollection
[ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202")] 
public sealed class XmlSchemaCollection : ICollection, IEnumerable
[ObsoleteAttribute(L"Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202")] 
public ref class XmlSchemaCollection sealed : ICollection, IEnumerable
/** @attribute ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202") */ 
public final class XmlSchemaCollection implements ICollection, IEnumerable
ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202") 
public final class XmlSchemaCollection implements ICollection, IEnumerable

Hinweise

Schemas werden mithilfe der Add-Methode geladen. Dabei wird das Schema einem Namespace-URI (Uniform Resource Identifier) zugeordnet. Bei XML-Schemas ist dies normalerweise die targetNamespace-Eigenschaft des Schemas.

Obwohl in dieser Klasse sowohl XML-Schemas als auch XDR-Schemas gespeichert werden, wird jede Methode oder Eigenschaft, die ein XmlSchema akzeptiert bzw. zurückgibt, nur auf XML-Schemas angewendet.

Diese Version des Produkts entspricht der Empfehlung des W3C (World Wide Web Consortium) für XML-Schemas unter http://www.w3.org/TR/xmlschema-1 und http://www.w3.org/TR/xmlschema-2. Ein XML-Schema muss im Schemaelement auf den W3C-Schema-Namespace http://www.w3.org/2001/XMLSchema verweisen. Ein Beispiel finden Sie unter der Add-Methode.

XmlSchemaCollection kann vom XmlValidatingReader für die effiziente Datenvalidierung verwendet werden.

Wichtig

Die XmlSchemaCollection-Klasse ist in Version 2.0 von Microsoft .NET Framework veraltet und wurde durch die XmlSchemaSet-Klasse ersetzt.

Beispiel

Im folgenden Beispiel wird ein XML-Dokument unter Verwendung der XmlSchemaCollection validiert.

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
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);
  }
}
#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();
}
import System.*;
import System.Xml.*;
import System.Xml.Schema.*;
import System.IO.*;

public class ValidXSD
{
    public static void main(String[] args)
    {
        XmlSchemaCollection sc = new XmlSchemaCollection();
        sc.add_ValidationEventHandler(new ValidationEventHandler(
            ValidationCallBack));
        sc.Add(null, "books.xsd");

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

            rdr.set_ValidationType(ValidationType.Schema);
            rdr.get_Schemas().Add(sc);
            rdr.add_ValidationEventHandler(new ValidationEventHandler(
                ValidationCallBack));
            while (rdr.Read()) {
            }
        }
    } //main

    private static void ValidationCallBack(Object sender,
        ValidationEventArgs e)
    {
        Console.WriteLine("Validation Error: {0}", e.get_Message());
    } //ValidationCallBack
} //ValidXSD

Vererbungshierarchie

System.Object
  System.Xml.Schema.XmlSchemaCollection

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 1.0, 1.1
Veraltet (Compilerwarnung) in 2.0

Siehe auch

Referenz

XmlSchemaCollection-Member
System.Xml.Schema-Namespace