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 数据简化 (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) XML 架构建议,该建议位于 XML 架构第 1 部分:结构和 XML 架构第 2 部分:数据类型。 XML 架构在其架构元素中必须引用 W3C 架构命名空间 http://www.w3.org/2001/XMLSchemaAdd有关示例,请参阅方法。

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

适用于