XmlSchemaSet クラスとは? わかりやすく解説

XmlSchemaSet クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

XML スキーマ定義言語 (XSD: XML Schema Definition Language) スキーマキャッシュ格納します

名前空間: System.Xml.Schema
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

public class XmlSchemaSet
public ref class XmlSchemaSet
public class XmlSchemaSet
public class XmlSchemaSet
解説解説

System.Xml Version 1.0 では、XML スキーマスキーマライブラリとして XmlSchemaCollection クラス読み込まれました。System.Xml Version 2.0 では、XmlValidatingReader クラスXmlSchemaCollection クラス使用されなくなりそれぞれ Create メソッドXmlSchemaSet クラス置き換えられています。

XmlSchemaSet は、標準との互換性パフォーマンス、および使用されなくなった XDR (XML-Data Reduced) スキーマ形式含め多く問題修正するために導入されました。

XmlSchemaCollection クラスXmlSchemaSet クラス比較次に示します

セキュリティについての考慮事項

使用例使用例

XmlReaderSettings オブジェクトSystem.Xml.XmlReader.Create メソッド使用してスキーマXML ドキュメント関連付ける例を次に示しますスキーマは、XmlReaderSettings オブジェクトの Schemas プロパティ追加されます。Schemas プロパティの値は XmlSchemaSet オブジェクトです。このスキーマは、XML ドキュメントスキーマ コンテンツ モデル準拠していることを検証するために使用されます。スキーマ検証エラー検証警告は、XmlReaderSettings オブジェクト定義された ValidationEventHandler で処理されます。

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

Class XmlSchemaSetExample

    Shared Sub Main()

        Dim booksSettings As XmlReaderSettings
 = New XmlReaderSettings()
        booksSettings.Schemas.Add("http://www.contoso.com/books",
 "contosoBooks.xsd")
        booksSettings.ValidationType = ValidationType.Schema
        AddHandler booksSettings.ValidationEventHandler, New
 ValidationEventHandler(AddressOf booksSettingsValidationEventHandler)

        Dim books As XmlReader = XmlReader.Create("contosoBooks.xml",
 booksSettings)

        While books.Read()

        End While

    End Sub

    Shared Sub booksSettingsValidationEventHandler(ByVal
 sender As Object, ByVal
 e As ValidationEventArgs)

        If e.Severity = XmlSeverityType.Warning Then
            Console.Write("WARNING: ")
            Console.WriteLine(e.Message)

        ElseIf e.Severity = XmlSeverityType.Error Then
            Console.Write("ERROR: ")
            Console.WriteLine(e.Message)
        End If

    End Sub

End Class
using System;
using System.Xml;
using System.Xml.Schema;

class XmlSchemaSetExample
{
    static void Main()
    {
        XmlReaderSettings booksSettings = new XmlReaderSettings();
        booksSettings.Schemas.Add("http://www.contoso.com/books",
 "contosoBooks.xsd");
        booksSettings.ValidationType = ValidationType.Schema;
        booksSettings.ValidationEventHandler += new ValidationEventHandler(booksSettingsValidationEventHandler);

        XmlReader books = XmlReader.Create("contosoBooks.xml", booksSettings);

        while (books.Read()) { }
    }

    static void booksSettingsValidationEventHandler(object
 sender, ValidationEventArgs e)
    {
        if (e.Severity == XmlSeverityType.Warning)
        {
            Console.Write("WARNING: ");
            Console.WriteLine(e.Message);
        }
        else if (e.Severity == XmlSeverityType.Error)
        {
            Console.Write("ERROR: ");
            Console.WriteLine(e.Message);
        }
    }
}
#using <System.Xml.dll>

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

static void booksSettingsValidationEventHandler(
 Object^ /*sender*/, ValidationEventArgs^ e )
{
   if ( e->Severity == XmlSeverityType::Warning )
   {
      Console::Write( L"WARNING: " );
      Console::WriteLine( e->Message );
   }
   else
   if ( e->Severity == XmlSeverityType::Error )
   {
      Console::Write( L"ERROR: " );
      Console::WriteLine( e->Message );
   }
}

int main()
{
   XmlReaderSettings^ booksSettings = gcnew XmlReaderSettings;
   booksSettings->Schemas->Add( L"http://www.contoso.com/books",
 L"books.xsd" );
   booksSettings->ValidationType = ValidationType::Schema;
   booksSettings->ValidationEventHandler += gcnew ValidationEventHandler( booksSettingsValidationEventHandler
 );
   XmlReader^ books = XmlReader::Create( L"books.xml", booksSettings );
   while ( books->Read() )
   {}

   return 0;
}

この例では、入力として books.xml というファイル使用してます。

<bookstore xmlns="http://www.contoso.com/books">
  <book genre="autobiography"
 publicationdate="1981" ISBN="1-861003-11-0">
    <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" publicationdate="1967"
 ISBN="0-201-63361-2">
    <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" publicationdate="1991"
 ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

この例では、入力として books.xsd というファイル使用してます。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
 elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="bookstore">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded"
 name="book">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element
 name="title" type="xs:string" />
                            <xs:element
 name="author">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element
 minOccurs="0" name="name" type="xs:string" />
                                        <xs:element
 minOccurs="0" name="first-name" type="xs:string"
 />
                                        <xs:element
 minOccurs="0" name="last-name" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element
 name="price" type="xs:decimal" />
                        </xs:sequence>
                        <xs:attribute
 name="genre" type="xs:string" use="required" />
                        <xs:attribute
 name="publicationdate" type="xs:unsignedShort" use="required"
 />
                        <xs:attribute
 name="ISBN" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
継承階層継承階層
System.Object
  System.Xml.Schema.XmlSchemaSet
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlSchemaSet メンバ
System.Xml.Schema 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「XmlSchemaSet クラス」の関連用語

XmlSchemaSet クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlSchemaSet クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS