XmlSchemaCollection 類別

定義

警告

Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202

警告

XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation.

警告

XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation instead.

警告

Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202

包含 XML 結構描述定義語言 (XSD) 和 XML-Data Reduced (XDR) 結構描述的快取。 XmlSchemaCollection 類別已經過時。 請改用 XmlSchemaSet

public ref class XmlSchemaCollection sealed : System::Collections::ICollection
[System.Obsolete("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202")]
public sealed class XmlSchemaCollection : System.Collections.ICollection
[System.Obsolete("XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation.")]
public sealed class XmlSchemaCollection : System.Collections.ICollection
[System.Obsolete("XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation instead.")]
public sealed class XmlSchemaCollection : 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
public sealed class XmlSchemaCollection : System.Collections.ICollection
[<System.Obsolete("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. https://go.microsoft.com/fwlink/?linkid=14202")>]
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
[<System.Obsolete("XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation.")>]
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
[<System.Obsolete("XmlSchemaCollection has been deprecated. Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation instead.")>]
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
[<System.Obsolete("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202")>]
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class XmlSchemaCollection
Implements ICollection
繼承
XmlSchemaCollection
屬性
實作

範例

下列範例會使用 XmlSchemaCollection 來驗證 XML 檔。

#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.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

備註

架構會使用 Add 方法來載入,此時架構會與命名空間統一資源識別項 (URI) 相關聯。 針對 XML 架構,這通常是 targetNamespace 架構的 屬性。

雖然這個類別同時儲存 XML 架構和 XDR 架構,但是任何接受或傳回 XmlSchema 的 方法和屬性都僅適用于 XML 架構。

此版本的產品支援 W3C (W3C) XML 架構建議,其位於 XML 架構第 1 部分:結構和 XML 架構第 2 部分:資料類型。 XML 架構必須參考其架構專案中的 W3C 架構命名空間 http://www.w3.org/2001/XMLSchema 。 如需範例, Add 請參閱 方法。

XmlSchemaCollection 可用於 XmlValidatingReader 有效率的資料驗證。

重要

類別 XmlSchemaCollection 在 Microsoft .NET Framework 2.0 版中已經過時,且已由 XmlSchemaSet 類別取代。

建構函式

XmlSchemaCollection()

初始化 XmlSchemaCollection 類別的新執行個體。

XmlSchemaCollection(XmlNameTable)

使用指定的 XmlSchemaCollection 初始化 XmlNameTable 類別的新執行個體。 載入結構描述時會使用 XmlNameTable

屬性

Count

取得這個集合中定義的命名空間數目。

Item[String]

取得與指定的命名空間 URI 關聯的 XmlSchema

NameTable

取得載入新結構描述時 XmlNameTable 使用的預設 XmlSchemaCollection

方法

Add(String, String)

將指定的 URL 找到的結構描述加入結構描述集合中。

Add(String, XmlReader)

加入包含在 XmlReader 中的結構描述至結構描述集合。

Add(String, XmlReader, XmlResolver)

加入包含在 XmlReader 中的結構描述至結構描述集合。 指定的 XmlResolver,用來解析任何的外部資源。

Add(XmlSchema)

XmlSchema 加入至集合中。

Add(XmlSchema, XmlResolver)

XmlSchema 加入至集合中。 指定的 XmlResolver,用來解析任何的外部參考。

Add(XmlSchemaCollection)

將指定的集合中定義的所有命名空間 (包含其相關的結構描述) 加入這個集合。

Contains(String)

取得值,表示具有指定命名空間的結構描述是否在集合中。

Contains(XmlSchema)

取得值,表示指定的 XmlSchematargetNamespace 是否在集合中。

CopyTo(XmlSchema[], Int32)

將這個集合中所有的 XmlSchema 物件複製到從指定索引開始的指定陣列中。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

提供以「各自獨立」方式逐一查看結構描述集合的支援。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

事件

ValidationEventHandler

設定事件處理常式,接收關於 XDR 和 XML 結構描述驗證錯誤的資訊。

明確介面實作

ICollection.CopyTo(Array, Int32)

如需這個成員的說明,請參閱 CopyTo(XmlSchema[], Int32)

ICollection.Count

如需這個成員的說明,請參閱 Count

ICollection.IsSynchronized

如需這個成員的說明,請參閱 ICollection.IsSynchronized

ICollection.SyncRoot

如需這個成員的說明,請參閱 ICollection.SyncRoot

IEnumerable.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於