XmlSchemaCollection XmlSchemaCollection XmlSchemaCollection XmlSchemaCollection Class

定义

警告

此 API 现已过时。

包含 XML 架构定义语言 (XSD) 和 XML 数据简化 (XDR) 架构的缓存。Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. XmlSchemaCollection 类已过时。The XmlSchemaCollection class is obsolete. 请改用 XmlSchemaSetUse 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")]
[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
type XmlSchemaCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class XmlSchemaCollection
Implements ICollection
继承
XmlSchemaCollectionXmlSchemaCollectionXmlSchemaCollectionXmlSchemaCollection
属性
实现

示例

下面的示例使用XmlSchemaCollection验证 XML 文档。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.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) 相关联。Schemas are loaded using the Add method, at which time the schema is associated with a namespace Uniform Resource Identifier (URI). 对于 XML 架构, 这通常是targetNamespace架构的属性。For XML Schemas, this will typically be the targetNamespace property of the schema.

尽管此类存储 xml 架构和 XDR 架构, 但使用或返回的XmlSchema任何方法和属性都仅适用于 XML 架构。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.

此版本的产品支持位于xml 架构第1部分的万维网联合会 (W3C) xml 架构建议:结构XML 架构第 2 部分:数据类型。This version of the product supports the World Wide Web Consortium (W3C) XML Schema recommendation located at XML Schema Part 1: Structures and XML Schema Part 2: Datatypes. XML 架构必须引用其 schema 元素中的http://www.w3.org/2001/XMLSchema W3C 架构命名空间。An XML Schema must reference the W3C Schema namespace http://www.w3.org/2001/XMLSchema in its schema element. 有关示例, 请参阅方法。AddSee the Add method for an example.

XmlSchemaCollection可以使用XmlValidatingReader来有效地进行数据验证。XmlSchemaCollection can be used by XmlValidatingReader for efficient data validation.

重要

类在 Microsoft .NET Framework 版本2.0 中已过时, 已被XmlSchemaSet类取代。 XmlSchemaCollectionThe XmlSchemaCollection class is obsolete in the Microsoft .NET Framework version 2.0 and has been replaced by the XmlSchemaSet class.

构造函数

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

初始化 XmlSchemaCollection 类的新实例。Initializes a new instance of the XmlSchemaCollection class.

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

使用指定的 XmlSchemaCollection 初始化 XmlNameTable 类的新实例。Initializes a new instance of the XmlSchemaCollection class with the specified XmlNameTable. 加载架构时使用 XmlNameTableThe XmlNameTable is used when loading schemas.

属性

Count Count Count Count

获取在该集合中定义的命名空间的数目。Gets the number of namespaces defined in this collection.

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

获取与给定的命名空间 URI 关联的 XmlSchemaGets the XmlSchema associated with the given namespace URI.

NameTable NameTable NameTable NameTable

获取加载新架构时由 XmlNameTable 使用的默认 XmlSchemaCollectionGets the default XmlNameTable used by the XmlSchemaCollection when loading new schemas.

方法

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

将由给定的 URL 定位的架构添加到架构集合中。Adds the schema located by the given URL into the schema collection.

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

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)

XmlReader 中包含的架构添加到架构集合中。Adds the schema contained in the XmlReader to the schema collection. 指定的 XmlResolver 用于解析任何可能引用的外部资源。The specified XmlResolver is used to resolve any external resources.

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

XmlSchema 添加到集合。Adds the XmlSchema to the collection.

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

XmlSchema 添加到集合。Adds the XmlSchema to the collection. 用指定的 XmlResolver 解析任何外部引用。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)

获取一个值,该值指示指定的 XmlSchematargetNamespace 是否在集合中。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)

将该集合中的所有 XmlSchema 对象复制到起始位置为给定索引的给定数组中。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()

获取当前实例的 TypeGets the Type of the current instance.

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

创建当前 Object 的浅表副本。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)

事件

ValidationEventHandler ValidationEventHandler ValidationEventHandler ValidationEventHandler

设置事件处理程序,以接收 XDR 和 XML 架构验证错误的相关信息。Sets an event handler for receiving information about the XDR and XML schema validation errors.

显式界面实现

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

有关此成员的说明,请参见 CopyTo(XmlSchema[], Int32)For a description of this member, see CopyTo(XmlSchema[], Int32).

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

有关此成员的说明,请参见 CountFor a description of this member, see Count.

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

有关此成员的说明,请参见 ICollection.IsSynchronizedFor a description of this member, see ICollection.IsSynchronized.

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

有关此成员的说明,请参见 ICollection.SyncRootFor a description of this member, see ICollection.SyncRoot.

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

有关此成员的说明,请参见 GetEnumerator()For a description of this member, see GetEnumerator().

扩展方法

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

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

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

根据指定类型筛选 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)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于