XmlSchemaCollection.Add 方法

定義

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

多載

Add(XmlSchema)

XmlSchema 加入至集合中。

Add(XmlSchemaCollection)

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

Add(String, String)

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

Add(String, XmlReader)

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

Add(XmlSchema, XmlResolver)

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

Add(String, XmlReader, XmlResolver)

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

備註

重要

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

Add(XmlSchema)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

XmlSchema 加入至集合中。

public:
 System::Xml::Schema::XmlSchema ^ Add(System::Xml::Schema::XmlSchema ^ schema);
public System.Xml.Schema.XmlSchema? Add (System.Xml.Schema.XmlSchema schema);
public System.Xml.Schema.XmlSchema Add (System.Xml.Schema.XmlSchema schema);
member this.Add : System.Xml.Schema.XmlSchema -> System.Xml.Schema.XmlSchema
Public Function Add (schema As XmlSchema) As XmlSchema

參數

schema
XmlSchema

要加入至集合的 XmlSchema

傳回

XmlSchema 物件。

備註

屬性 targetNamespace 是用來識別這個架構。

如果加入的架構包含透過 include 和 元素 (的其他命名空間參考) ,則 import 應用程式的信任層級會決定這些其他命名空間的解析方式。 (在 .NET Framework 1.0 版中,一律會使用預設值 XmlUrlResolver) 。

Fully trusted code: 沒有使用者認證的預設值 XmlUrlResolver 是用來解析任何外部資源。 這些其他命名空間的架構只會針對驗證目的載入。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。 如果這些外部資源位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

Semi-trusted code: 不會解析外部參考。

注意

如果使用 屬性存取 , XmlSchemaCollection 方法會 Add 使用 XmlResolver 屬性所 XmlValidatingReader.XmlResolverXmlValidatingReader.Schemas 指定的 。

重要

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

另請參閱

適用於

Add(XmlSchemaCollection)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

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

public:
 void Add(System::Xml::Schema::XmlSchemaCollection ^ schema);
public void Add (System.Xml.Schema.XmlSchemaCollection schema);
member this.Add : System.Xml.Schema.XmlSchemaCollection -> unit
Public Sub Add (schema As XmlSchemaCollection)

參數

schema
XmlSchemaCollection

您要加入至這個集合的 XmlSchemaCollection

備註

如果加入的架構包含透過 includeimport 專案 (的其他命名空間參考,或 x-schema 屬性) ,應用程式的信任層級會決定如何解析這些其他命名空間。 (在 .NET Framework 1.0 版中,一律會使用預設值 XmlUrlResolver) 。

Fully trusted code: 沒有使用者認證的預設值 XmlUrlResolver 是用來解析任何外部資源。 這些其他命名空間的架構只會針對驗證目的載入。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。 如果這些外部資源位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

Semi-trusted code: 不會解析外部參考。

注意

如果使用 屬性存取 , XmlSchemaCollection 方法會 Add 使用 XmlResolver 屬性所 XmlValidatingReader.XmlResolverXmlValidatingReader.Schemas 指定的 。

重要

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

適用於

Add(String, String)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

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

public:
 System::Xml::Schema::XmlSchema ^ Add(System::String ^ ns, System::String ^ uri);
public System.Xml.Schema.XmlSchema? Add (string? ns, string uri);
public System.Xml.Schema.XmlSchema Add (string ns, string uri);
member this.Add : string * string -> System.Xml.Schema.XmlSchema
Public Function Add (ns As String, uri As String) As XmlSchema

參數

ns
String

與結構描述關聯的命名空間 URI。 對於 XML 結構描述而言,這通常會是 targetNamespace

uri
String

指定要載入之結構描述的 URL。

傳回

加入結構描述集合的 XmlSchema,如果加入的結構描述是 XDR 結構描述,或者結構描述中有編譯錯誤,則為 null

例外狀況

結構描述不是有效的結構描述。

範例

下列範例會使用 儲存在 中的 XmlSchemaCollection 架構來驗證三個 XML 檔案。

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Schema;

public ref class SchemaCollectionSample
{
private:
   XmlTextReader^ reader;
   XmlValidatingReader^ vreader;
   Boolean m_success;

public:
   SchemaCollectionSample()
   {
      reader = nullptr;
      vreader = nullptr;
      m_success = true;

      //Load the schema collection.
      XmlSchemaCollection^ xsc = gcnew XmlSchemaCollection;
      String^ schema = "books.xsd";
      String^ schema1 = "schema1.xdr";
      xsc->Add( "urn:bookstore-schema", schema ); //XSD schema
      xsc->Add( "urn:newbooks-schema", schema1 ); //XDR schema
      String^ doc1 = "booksSchema.xml";
      String^ doc2 = "booksSchemaFail.xml";
      String^ doc3 = "newbooks.xml";

      //Validate the files using schemas stored in the collection.
      Validate( doc1, xsc ); //Should pass.
      Validate( doc2, xsc ); //Should fail.   
      Validate( doc3, xsc ); //Should fail. 
   }


private:
   void Validate( String^ filename, XmlSchemaCollection^ xsc )
   {
      m_success = true;
      Console::WriteLine();
      Console::WriteLine( "Validating XML file {0}...", filename );
      reader = gcnew XmlTextReader( filename );

      //Create a validating reader.
      vreader = gcnew XmlValidatingReader( reader );

      //Validate using the schemas stored in the schema collection.
      vreader->Schemas->Add( xsc );

      //Set the validation event handler
      vreader->ValidationEventHandler += gcnew ValidationEventHandler( this, &SchemaCollectionSample::ValidationCallBack );

      //Read and validate the XML data.
      while ( vreader->Read() )
      {}

      Console::WriteLine( "Validation finished. Validation {0}", (m_success == true ? (String^)"successful" : "failed") );
      Console::WriteLine();

      //Close the reader.
      vreader->Close();
   }

   void ValidationCallBack( Object^ /*sender*/, ValidationEventArgs^ args )
   {
      m_success = false;
      Console::Write( "\r\n\tValidation error: {0}", args->Message );
   }

};

int main()
{
   gcnew SchemaCollectionSample;
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class SchemaCollectionSample
{
  private const String doc1 = "booksSchema.xml";
  private const String doc2 = "booksSchemaFail.xml";
  private const String doc3 = "newbooks.xml";
  private const String schema = "books.xsd";
  private const String schema1 = "schema1.xdr";

  private XmlTextReader reader=null;
  private XmlValidatingReader vreader = null;
  private Boolean m_success = true;

  public SchemaCollectionSample ()
  {
    //Load the schema collection.
    XmlSchemaCollection xsc = new XmlSchemaCollection();
    xsc.Add("urn:bookstore-schema", schema);  //XSD schema
    xsc.Add("urn:newbooks-schema", schema1);  //XDR schema

    //Validate the files using schemas stored in the collection.
    Validate(doc1, xsc); //Should pass.
    Validate(doc2, xsc); //Should fail.
    Validate(doc3, xsc); //Should fail.
  }

  public static void Main ()
  {
      SchemaCollectionSample validation = new SchemaCollectionSample();
  }

  private void Validate(String filename, XmlSchemaCollection xsc)
  {

     m_success = true;
     Console.WriteLine();
     Console.WriteLine("Validating XML file {0}...", filename.ToString());
     reader = new XmlTextReader (filename);

     //Create a validating reader.
    vreader = new XmlValidatingReader (reader);

     //Validate using the schemas stored in the schema collection.
     vreader.Schemas.Add(xsc);

     //Set the validation event handler
     vreader.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
     //Read and validate the XML data.
     while (vreader.Read()){}
     Console.WriteLine ("Validation finished. Validation {0}", (m_success==true ? "successful" : "failed"));
     Console.WriteLine();

     //Close the reader.
     vreader.Close();
  }

  private void ValidationCallBack (object sender, ValidationEventArgs args)
  {
     m_success = false;

     Console.Write("\r\n\tValidation error: " + args.Message);
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml
Imports System.Xml.Schema

Public Class SchemaCollectionSample
    Private doc1 As String = "booksSchema.xml"
    Private doc2 As String = "booksSchemaFail.xml"
    Private doc3 As String = "newbooks.xml"
    Private schema As String = "books.xsd"
    Private schema1 As String = "schema1.xdr"
    
    Private reader As XmlTextReader = Nothing
    Private vreader As XmlValidatingReader = Nothing
    Private m_success As Boolean = True
    
    Public Sub New()

            'Load the schema collection
            Dim xsc As New XmlSchemaCollection()
            xsc.Add("urn:bookstore-schema", schema) 'XSD schema
            xsc.Add("urn:newbooks-schema", schema1) 'XDR schema

            'Validate the files using schemas stored in the collection.
            Validate(doc1, xsc) 'Should pass.
            Validate(doc2, xsc) 'Should fail.   
            Validate(doc3, xsc) 'Should fail. 
        
    End Sub
    
    Public Shared Sub Main()
        Dim validation As New SchemaCollectionSample()
    End Sub
    
    Private Sub Validate(filename As String, xsc As XmlSchemaCollection)
        
            m_success = True
            Console.WriteLine()
            Console.WriteLine("Validating XML file {0}...", filename.ToString())
            reader = New XmlTextReader(filename)
            
            'Create a validating reader.
            vreader = New XmlValidatingReader(reader)
            
            'Use the schemas stored in the schema collection.
            vreader.Schemas.Add(xsc)
            
            'Set the validation event handler.
            AddHandler vreader.ValidationEventHandler, AddressOf ValidationCallBack
            'Read and validate the XML data.
            While vreader.Read()
            End While
            Console.WriteLine("Validation finished. Validation {0}", IIf(m_success, "successful", "failed"))
            Console.WriteLine()

            'Close the reader.
            vreader.Close()

    End Sub
       
    
    Private Sub ValidationCallBack(sender As Object, args As ValidationEventArgs)
        m_success = False
        
        Console.Write((ControlChars.CrLf & ControlChars.Tab & "Validation error: " & args.Message))
    End Sub
End Class

此範例會使用下列五個輸入檔:

booksSchema.xml


<?xml version='1.0'?>
 <bookstore xmlns="urn:bookstore-schema">
   <book genre="autobiography">
     <title>The Autobiography of Benjamin Franklin</title>
     <author>
       <first-name>Benjamin</first-name>
       <last-name>Franklin</last-name>
     </author>
     <price>8.99</price>
   </book>
   <book genre="novel">
     <title>The Confidence Man</title>
     <author>
       <first-name>Herman</first-name>
       <last-name>Melville</last-name>
     </author>
     <price>11.99</price>
   </book>
 </bookstore>

booksSchemaFail.xml


<?xml version='1.0'?>
 <bookstore xmlns="urn:bookstore-schema">
   <book>
     <author>
       <first-name>Benjamin</first-name>
       <last-name>Franklin</last-name>
     </author>
   </book>
   <book genre="novel">
     <title>The Confidence Man</title>
     <author>
       <first-name>Herman</first-name>
       <last-name>Melville</last-name>
     </author>
     <price>11.99</price>
   </book>
   <book genre="philosophy">
     <title>The Gorgias</title>
     <author>
       <name>Plato</name>
     </author>
     <price>9.99</price>
   </book>
 </bookstore>

newbooks.xml


<?xml version='1.0'?>
<bookstore xmlns="urn:newbooks-schema">
  <book genre="novel" style="hardcover">
    <title>The Handmaid's Tale</title>
    <author>
      <first-name>Margaret</first-name>
      <last-name>Atwood</last-name>
    </author>
    <price>19.95</price>
  </book>
  <book genre="novel" style="other">
    <title>The Poisonwood Bible</title>
    <author>
      <first-name>Barbara</first-name>
      <last-name>Kingsolver</last-name>
    </author>
    <price>11.99</price>
  </book>
</bookstore>

books.xsd


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns="urn:bookstore-schema"
     elementFormDefault="qualified"
     targetNamespace="urn:bookstore-schema">
 
  <xsd:element name="bookstore" type="bookstoreType"/>
 
  <xsd:complexType name="bookstoreType">
   <xsd:sequence maxOccurs="unbounded">
    <xsd:element name="book"  type="bookType"/>
   </xsd:sequence>
  </xsd:complexType>
 
  <xsd:complexType name="bookType">
   <xsd:sequence>
    <xsd:element name="title" type="xsd:string"/>
    <xsd:element name="author" type="authorName"/>
    <xsd:element name="price"  type="xsd:decimal"/>
   </xsd:sequence>
   <xsd:attribute name="genre" type="xsd:string"/>
  </xsd:complexType>
 
  <xsd:complexType name="authorName">
   <xsd:sequence>
    <xsd:element name="first-name"  type="xsd:string"/>
    <xsd:element name="last-name" type="xsd:string"/>
   </xsd:sequence>
  </xsd:complexType>
 
 </xsd:schema>

schema1.xdr


<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <ElementType name="first-name" content="textOnly"/>
  <ElementType name="last-name" content="textOnly"/>
  <ElementType name="name" content="textOnly"/>
  <ElementType name="price" content="textOnly" dt:type="fixed.14.4"/>
  <ElementType name="author" content="eltOnly" order="one">
    <group order="seq">
      <element type="name"/>
    </group>
    <group order="seq">
      <element type="first-name"/>
      <element type="last-name"/>
    </group>
  </ElementType>
  <ElementType name="title" content="textOnly"/>
  <AttributeType name="genre" dt:type="string"/>
  <AttributeType name="style" dt:type="enumeration"
        dt:values="paperback hardcover"/>
  <ElementType name="book" content="eltOnly">
    <attribute type="genre" required="yes"/>
    <attribute type="style" required="yes"/>
    <element type="title"/>
    <element type="author"/>
    <element type="price"/>
  </ElementType>
  <ElementType name="bookstore" content="eltOnly">
    <element type="book"/>
  </ElementType>
</Schema>

備註

如果 ns 已經與集合中的另一個架構相關聯,則加入的架構會取代集合中的原始架構。 例如,在下列 C# 程式碼中,authors.xsd 會從集合中移除,並新增 names.xsd。

schemaColl.Add("urn:author", "authors.xsd");  
schemaColl.Add("urn:author", "names.xsd");  

如果 是 nullns 且要加入的架構是 XML 架構,則 Add 方法會使用 targetNamespace XML 架構中定義的 來識別集合中的架構。 如果加入的架構包含透過 includeimport 專案 (的其他命名空間參考,或 x-schema 屬性) ,應用程式的信任層級會決定如何解析這些其他命名空間。 (在 .NET Framework 1.0 版中,一律會使用預設值 XmlUrlResolver) 。

Fully trusted code: 沒有使用者認證的預設值 XmlUrlResolver 是用來解析任何外部資源。 這些其他命名空間的架構只會針對驗證目的載入。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。 如果這些外部資源位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

Semi-trusted code: 不會解析外部參考。

注意

如果使用 屬性存取 , XmlSchemaCollection 方法會 Add 使用 XmlResolver 屬性所 XmlValidatingReader.XmlResolverXmlValidatingReader.Schemas 指定的 。

重要

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

適用於

Add(String, XmlReader)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

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

public:
 System::Xml::Schema::XmlSchema ^ Add(System::String ^ ns, System::Xml::XmlReader ^ reader);
public System.Xml.Schema.XmlSchema? Add (string? ns, System.Xml.XmlReader reader);
public System.Xml.Schema.XmlSchema Add (string ns, System.Xml.XmlReader reader);
member this.Add : string * System.Xml.XmlReader -> System.Xml.Schema.XmlSchema
Public Function Add (ns As String, reader As XmlReader) As XmlSchema

參數

ns
String

與結構描述關聯的命名空間 URI。 對於 XML 結構描述而言,這通常會是 targetNamespace

reader
XmlReader

包含要加入之結構描述的 XmlReader

傳回

加入結構描述集合的 XmlSchema,如果加入的結構描述是 XDR 結構描述,或者結構描述中有編譯錯誤,則為 null

例外狀況

結構描述不是有效的結構描述。

備註

如果 ns 已經與集合中的另一個架構相關聯,則加入的架構會取代集合中的原始架構。

如果 是 nullns 且要加入的架構是 XML 架構,則 Add 方法會使用 targetNamespace XML 架構中定義的 來識別集合中的架構。

如果加入的架構包含透過 includeimport 專案 (的其他命名空間參考,或 x-schema 屬性) ,應用程式的信任層級會決定如何解析這些其他命名空間。 (在 .NET Framework 1.0 版中,一律會使用預設值 XmlUrlResolver) 。

Fully trusted code: 沒有使用者認證的預設值 XmlUrlResolver 是用來解析任何外部資源。 這些其他命名空間的架構只會針對驗證目的載入。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。 如果這些外部資源位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

Semi-trusted code: 不會解析外部參考。

注意

如果使用 屬性存取 , XmlSchemaCollection 方法會 Add 使用 XmlResolver 屬性所 XmlValidatingReader.XmlResolverXmlValidatingReader.Schemas 指定的 。

重要

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

適用於

Add(XmlSchema, XmlResolver)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

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

public:
 System::Xml::Schema::XmlSchema ^ Add(System::Xml::Schema::XmlSchema ^ schema, System::Xml::XmlResolver ^ resolver);
public System.Xml.Schema.XmlSchema? Add (System.Xml.Schema.XmlSchema schema, System.Xml.XmlResolver? resolver);
public System.Xml.Schema.XmlSchema Add (System.Xml.Schema.XmlSchema schema, System.Xml.XmlResolver resolver);
member this.Add : System.Xml.Schema.XmlSchema * System.Xml.XmlResolver -> System.Xml.Schema.XmlSchema
Public Function Add (schema As XmlSchema, resolver As XmlResolver) As XmlSchema

參數

schema
XmlSchema

要加入至集合的 XmlSchema

resolver
XmlResolver

XmlResolver,用來解析 includeimport 項目中參考的命名空間。 如果這個值是 null,就不會解析外部參考。

傳回

要加入至結構描述集合中的 XmlSchema

例外狀況

結構描述不是有效的結構描述。

範例

下列範例會將架構新增至集合。 XmlUrlResolver會傳遞至 方法, Add 以設定存取架構中所參考之任何外部資源所需的必要認證。

XmlSchemaCollection^ sc = gcnew XmlSchemaCollection;
sc->ValidationEventHandler += gcnew ValidationEventHandler( Sample::ValidationCallBack );

// Create a resolver with the necessary credentials.
XmlUrlResolver^ resolver = gcnew XmlUrlResolver;
System::Net::NetworkCredential^ nc;
nc = gcnew System::Net::NetworkCredential( UserName,SecurelyStoredPassword,Domain );
resolver->Credentials = nc;

// Add the new schema to the collection.
sc->Add( nullptr, gcnew XmlTextReader( "sample.xsd" ), resolver );
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);

// Create a resolver with the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Add the new schema to the collection.
sc.Add("", new XmlTextReader("sample.xsd"), resolver);
Dim sc As XmlSchemaCollection = New XmlSchemaCollection()
AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack

' Create a resolver with the necessary credentials.
Dim resolver As XmlUrlResolver = New XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials

' Add the new schema to the collection.
sc.Add("", New XmlTextReader("sample.xsd"), resolver)

備註

屬性 targetNamespace 是用來識別這個架構。

如果架構包含參考其他命名空間的 includeimport 元素,這些其他命名空間的架構只會針對驗證目的載入。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。

重要

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

另請參閱

適用於

Add(String, XmlReader, XmlResolver)

Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs
Source:
XmlSchemaCollection.cs

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

public:
 System::Xml::Schema::XmlSchema ^ Add(System::String ^ ns, System::Xml::XmlReader ^ reader, System::Xml::XmlResolver ^ resolver);
public System.Xml.Schema.XmlSchema? Add (string? ns, System.Xml.XmlReader reader, System.Xml.XmlResolver? resolver);
public System.Xml.Schema.XmlSchema Add (string ns, System.Xml.XmlReader reader, System.Xml.XmlResolver resolver);
member this.Add : string * System.Xml.XmlReader * System.Xml.XmlResolver -> System.Xml.Schema.XmlSchema
Public Function Add (ns As String, reader As XmlReader, resolver As XmlResolver) As XmlSchema

參數

ns
String

與結構描述關聯的命名空間 URI。 對於 XML 結構描述而言,這通常會是 targetNamespace

reader
XmlReader

包含要加入之結構描述的 XmlReader

resolver
XmlResolver

XmlResolver,用來解析在 includeimport 項目或 x-schema 屬性 (XDR 結構描述) 中參考的命名空間。 如果這個值是 null,就不會解析外部參考。

傳回

加入結構描述集合的 XmlSchema,如果加入的結構描述是 XDR 結構描述,或者結構描述中有編譯錯誤,則為 null

例外狀況

結構描述不是有效的結構描述。

備註

如果 ns 已經與集合中的另一個架構相關聯,則加入的架構會取代集合中的原始架構。

如果 是 nullns 且要加入的架構是 XML 架構,則 Add 方法會使用 targetNamespace XML 架構中定義的 屬性來識別集合中的架構。

如果加入的架構包含透過 includeimport 專案 (的其他命名空間參考,或 x-schema 屬性) ,則只會針對驗證目的載入這些其他命名空間的架構。 不同于原始架構,這些其他架構不會明確新增至架構集合。 因此,您無法使用任何集合方法或屬性來存取它們。

重要

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

另請參閱

適用於