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 、このスキーマを識別するために使用されます。

追加されるスキーマに他の名前空間への参照 (および import 要素を介してinclude) が含まれている場合、アプリケーションの信頼レベルによって、これらの他の名前空間の解決方法が決まります。 (.NET Framework バージョン 1.0 では、既定値XmlUrlResolverが常に使用されていました)。

Fully trusted code: 外部リソースの解決には、ユーザー資格情報のない既定値 XmlUrlResolver が使用されます。 これらの他の名前空間のスキーマは、検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、どのコレクション メソッドまたはプロパティも使用してアクセスできません。 これらの外部リソースが認証を必要とするネットワーク リソース上にある場合は、引数の 1 つとして を XmlResolver 受け取り、必要な資格情報で を XmlResolver 指定するオーバーロードを使用します。

Semi-trusted code: 外部参照は解決されません。

注意

XmlSchemaCollectionが プロパティを使用してXmlValidatingReader.Schemasアクセスされている場合、 Add メソッドは プロパティで指定された をXmlResolverXmlValidatingReader.XmlResolver使用します。

重要

クラスは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

注釈

追加されるスキーマに他の名前空間への参照 (および import 要素または x-schema 属性を介してinclude) が含まれている場合、アプリケーションの信頼レベルによって、これらの他の名前空間の解決方法が決まります。 (.NET Framework バージョン 1.0 では、既定値XmlUrlResolverが常に使用されていました)。

Fully trusted code: 外部リソースの解決には、ユーザー資格情報のない既定値 XmlUrlResolver が使用されます。 これらの他の名前空間のスキーマは、検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、どのコレクション メソッドまたはプロパティも使用してアクセスできません。 これらの外部リソースが認証を必要とするネットワーク リソース上にある場合は、引数の 1 つとして を XmlResolver 受け取り、必要な資格情報で を XmlResolver 指定するオーバーロードを使用します。

Semi-trusted code: 外部参照は解決されません。

注意

XmlSchemaCollectionが プロパティを使用してXmlValidatingReader.Schemasアクセスされている場合、 Add メソッドは プロパティで指定された をXmlResolverXmlValidatingReader.XmlResolver使用します。

重要

クラスは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

例外

スキーマが、有効なスキーマではありません。

次の例では、 に格納されているスキーマを使用して 3 つの XML ファイルを XmlSchemaCollection検証します。

#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

このサンプルでは、次の 5 つの入力ファイルを使用します。

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");  

null で、追加されるスキーマが XML スキーマの場合nsAddメソッドは XML スキーマで定義されている を使用targetNamespaceしてコレクション内のスキーマを識別します。 追加されるスキーマに他の名前空間への参照 (および import 要素または x-schema 属性を介してinclude) が含まれている場合、アプリケーションの信頼レベルによって、これらの他の名前空間の解決方法が決まります。 (.NET Framework バージョン 1.0 では、既定値XmlUrlResolverが常に使用されていました)。

Fully trusted code: 外部リソースの解決には、ユーザー資格情報のない既定値 XmlUrlResolver が使用されます。 これらの他の名前空間のスキーマは、検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、どのコレクション メソッドまたはプロパティも使用してアクセスできません。 これらの外部リソースが認証を必要とするネットワーク リソース上にある場合は、引数の 1 つとして を XmlResolver 受け取り、必要な資格情報で を XmlResolver 指定するオーバーロードを使用します。

Semi-trusted code: 外部参照は解決されません。

注意

XmlSchemaCollectionが プロパティを使用してXmlValidatingReader.Schemasアクセスされている場合、 Add メソッドは プロパティで指定された をXmlResolverXmlValidatingReader.XmlResolver使用します。

重要

クラスは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 は、追加されるスキーマによってコレクション内の元のスキーマが置き換えられます。

null で、追加されるスキーマが XML スキーマの場合nsAddメソッドは XML スキーマで定義されている を使用targetNamespaceしてコレクション内のスキーマを識別します。

追加されるスキーマに他の名前空間への参照 (および import 要素または x-schema 属性を介してinclude) が含まれている場合、アプリケーションの信頼レベルによって、これらの他の名前空間の解決方法が決まります。 (.NET Framework バージョン 1.0 では、既定値XmlUrlResolverが常に使用されていました)。

Fully trusted code: 外部リソースの解決には、ユーザー資格情報のない既定値 XmlUrlResolver が使用されます。 これらの他の名前空間のスキーマは、検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、どのコレクション メソッドまたはプロパティも使用してアクセスできません。 これらの外部リソースが認証を必要とするネットワーク リソース上にある場合は、引数の 1 つとして を XmlResolver 受け取り、必要な資格情報で を XmlResolver 指定するオーバーロードを使用します。

Semi-trusted code: 外部参照は解決されません。

Note

XmlSchemaCollectionが プロパティを使用してXmlValidatingReader.Schemasアクセスされている場合、 Add メソッドは プロパティで指定された をXmlResolverXmlValidatingReader.XmlResolver使用します。

重要

クラスは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

include 要素および import 要素で参照される名前空間を解決するために使用される XmlResolver。 これが 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 、このスキーマを識別するために使用されます。

スキーマに他の include 名前空間を参照する 要素と import 要素が含まれている場合、これらの他の名前空間のスキーマは検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、コレクション メソッドまたはプロパティを使用してアクセスすることはできません。

重要

クラスは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

include 要素、import 要素、または x-schema 属性 (XDR スキーマ) で参照される名前空間を解決するために使用される XmlResolver。 これが null の場合は、外部参照が解決されません。

戻り値

スキーマ コレクションに追加される XmlSchema。追加されるスキーマが XDR スキーマであるか、またはスキーマにコンパイル エラーがある場合は null

例外

スキーマが、有効なスキーマではありません。

注釈

既にコレクション内の別のスキーマに関連付けられている場合 ns は、追加されるスキーマによってコレクション内の元のスキーマが置き換えられます。

null で、追加されるスキーマが XML スキーマの場合nsAddメソッドは XML スキーマで定義されている属性を使用targetNamespaceしてコレクション内のスキーマを識別します。

追加されるスキーマに他の名前空間 (および import 要素または 属性を介したinclude) への参照がx-schema含まれている場合、これらの他の名前空間のスキーマは検証目的でのみ読み込まれます。 元のスキーマとは異なり、これらの他のスキーマはスキーマ コレクションに明示的に追加されません。 その結果、コレクション メソッドまたはプロパティを使用してアクセスすることはできません。

重要

クラスはXmlSchemaCollection、.NET Framework バージョン 2.0 では古く、クラスにXmlSchemaSet置き換えられました。

こちらもご覧ください

適用対象