XmlReaderSettings.ValidationType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlReaderSettings.ValidationType プロパティの意味・解説 

XmlReaderSettings.ValidationType プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

XmlReader読み込むときに検証または型の割り当て実行するかどうかを示す値を取得または設定します

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

Public Property ValidationType As
 ValidationType
Dim instance As XmlReaderSettings
Dim value As ValidationType

value = instance.ValidationType

instance.ValidationType = value
public ValidationType ValidationType { get;
 set; }
public:
property ValidationType ValidationType {
    ValidationType get ();
    void set (ValidationType value);
}
/** @property */
public ValidationType get_ValidationType ()

/** @property */
public void set_ValidationType (ValidationType
 value)
public function get ValidationType
 () : ValidationType

public function set ValidationType
 (value : ValidationType)

プロパティ
ValidationType 値の 1 つ既定値ValidationType.None です。

解説解説
使用例使用例

XmlSchemaSet格納されているスキーマ使用して検証を行う例を次に示します

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

public class Sample 

  public shared sub Main()
 

    ' Create the XmlSchemaSet class.
    Dim sc as XmlSchemaSet = new
 XmlSchemaSet()

    ' Add the schema to the collection.
    sc.Add("urn:bookstore-schema", "books.xsd")

    ' Set the validation settings.
    Dim settings as XmlReaderSettings = new
 XmlReaderSettings()
    settings.ValidationType = ValidationType.Schema
    settings.Schemas = sc
    AddHandler settings.ValidationEventHandler, AddressOf
 ValidationCallBack
 
    ' Create the XmlReader object.
    Dim reader as XmlReader = XmlReader.Create("booksSchemaFail.xml",
 settings)

    ' Parse the file. 
    while reader.Read()
    end while
    
  end sub

  ' Display any validation errors.
  private shared sub ValidationCallBack(sender
 as object, e as ValidationEventArgs)
 
    Console.WriteLine("Validation Error: {0}", e.Message)
  end sub
end class
using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class Sample {

  public static void Main()
 {

    // Create the XmlSchemaSet class.
    XmlSchemaSet sc = new XmlSchemaSet();

    // Add the schema to the collection.
    sc.Add("urn:bookstore-schema", "books.xsd");

    // Set the validation settings.
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.Schemas = sc;
    settings.ValidationEventHandler += new ValidationEventHandler
 (ValidationCallBack);
 
    // Create the XmlReader object.
    XmlReader reader = XmlReader.Create("booksSchemaFail.xml", settings);

    // Parse the file. 
    while (reader.Read());
    
  }

  // Display any validation errors.
  private static void ValidationCallBack(object
 sender, ValidationEventArgs e) {
    Console.WriteLine("Validation Error: {0}", e.Message);
  }
}
#using <System.Xml.dll>

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

// Display any validation errors.
static void ValidationCallBack( Object^ /*sender*/,
 ValidationEventArgs^ e )
{
   Console::WriteLine( L"Validation Error: {0}", e->Message );
}

int main()
{
   // Create the XmlSchemaSet class.
   XmlSchemaSet^ sc = gcnew XmlSchemaSet;

   // Add the schema to the collection.
   sc->Add( L"urn:bookstore-schema", L"books.xsd" );

   // Set the validation settings.
   XmlReaderSettings^ settings = gcnew XmlReaderSettings;
   settings->ValidationType = ValidationType::Schema;
   settings->Schemas = sc;
   settings->ValidationEventHandler += gcnew ValidationEventHandler( ValidationCallBack
 );

   // Create the XmlReader object.
   XmlReader^ reader = XmlReader::Create( L"booksSchemaFail.xml", settings
 );

   // Parse the file. 
   while ( reader->Read() )
      ;

   return 1;
}

サンプルでは、次の入力ファイル使用します

booksSchemaFail.xml

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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からXmlReaderSettings.ValidationType プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からXmlReaderSettings.ValidationType プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からXmlReaderSettings.ValidationType プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

XmlReaderSettings.ValidationType プロパティのお隣キーワード
検索ランキング

   

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



XmlReaderSettings.ValidationType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS