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

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

XmlValidatingReader.ValidationType プロパティ

実行する検証タイプを示す値を取得または設定します

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

Public Property ValidationType As
 ValidationType
Dim instance As XmlValidatingReader
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.Auto が設定されます。

例外例外
例外種類条件

InvalidOperationException

Read呼び出した後、このプロパティ設定

解説解説
使用例使用例

2 つファイル検証する例を次に示します

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Imports Microsoft.VisualBasic

Public Class Sample
    Private doc1 As String
 = "notValid.xml"
    Private doc2 As String
 = "cdDTD.xml"
    Private doc3 As String
 = "book1.xml"
    
    Private txtreader As XmlTextReader = Nothing
    Private reader As XmlValidatingReader =
 Nothing
    Private m_success As Boolean
 = True
    
    Public Sub New()
        'Parse the files and validate when requested.
        Validate(doc1, ValidationType.XDR) 'Validation should fail.
        Validate(doc2, ValidationType.DTD) 'Validation should fail.
        Validate(doc3, ValidationType.None) 'No validation performed.
    End Sub 'New
    
    Public Shared Sub Main()
        Dim validation As New
 Sample()
    End Sub 'Main
    
    Private Sub Validate(filename As
 String, vt As ValidationType)
        Try
            'Implement the readers.  Set the ValidationType.
            txtreader = New XmlTextReader(filename)
            reader = New XmlValidatingReader(txtreader)
            reader.ValidationType = vt
            
            'If the reader is set to validate, set the event handler.
            If vt = ValidationType.None Then
                Console.WriteLine(ControlChars.Cr & "Parsing
 XML file " & filename.ToString())
            Else
                Console.WriteLine(ControlChars.Cr & "Validating
 XML file " & filename.ToString())
                m_success = True
                'Set the validation event handler.
                AddHandler reader.ValidationEventHandler, AddressOf
 ValidationCallBack
            End If
            
            ' Read XML data
            While reader.Read()
            End While 
            If vt = ValidationType.None Then
                Console.WriteLine("Finished parsing file.")
            Else
                Console.WriteLine("Validation finished. Validation
 {0}", IIf(m_success, "successful", "failed"))
            End If
        
        Finally
            'Close the reader.
            If Not (reader Is
 Nothing) Then
                reader.Close()
            End If
        End Try 
    End Sub 'Validate
    
    'Display the validation errors.
    Private Sub ValidationCallBack(sender As
 Object, args As ValidationEventArgs)
        m_success = False
        
        Console.Write(ControlChars.CrLf & ControlChars.Tab & "Validation
 error: " & args.Message)
    End Sub 'ValidationCallBack
End Class 'Sample
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Sample
{
  private const String doc1 = "notValid.xml";
  private const String doc2 = "cdDTD.xml";
  private const String doc3 = "book1.xml";

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

  public Sample ()
  {
      //Parse the files and validate when requested.
      Validate(doc1, ValidationType.XDR);  //Validation should fail.
      Validate(doc2, ValidationType.DTD);  //Validation should fail.
      Validate(doc3, ValidationType.None); //No validation performed.

  }    

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

  private void Validate(String filename, ValidationType
 vt)
  {
    try
    {    
        //Implement the readers.  Set the ValidationType.
        txtreader = new XmlTextReader(filename);
        reader = new XmlValidatingReader(txtreader);
        reader.ValidationType = vt;

        //If the reader is set to validate, set the event handler.
        if (vt==ValidationType.None)
           Console.WriteLine("\nParsing XML file " + filename.ToString());
        else{
           Console.WriteLine("\nValidating XML file " + filename.ToString());
           m_success = true;
           //Set the validation event handler.
           reader.ValidationEventHandler += new ValidationEventHandler
 (ValidationCallBack);
        }

        // Read XML data
        while (reader.Read()){}

        if (vt==ValidationType.None)
           Console.WriteLine("Finished parsing file.");
        else
          Console.WriteLine ("Validation finished. Validation {0}", (m_success==true
 ? "successful" : "failed"));
     }

     finally
     {
        //Close the reader.
        if (reader != null)
          reader.Close();
     } 

  }
  
  //Display the validation errors.
  private void ValidationCallBack (object sender,
 ValidationEventArgs args)
  {
     m_success = false;

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

  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Schema;
public ref class Sample
{
private:
   XmlTextReader^ txtreader;
   XmlValidatingReader^ reader;
   Boolean m_success;

public:
   Sample()
   {
      txtreader = nullptr;
      reader = nullptr;
      m_success = true;
      String^ doc1 = "notValid.xml";
      String^ doc2 = "cdDTD.xml";
      String^ doc3 = "book1.xml";
      
      //Parse the files and validate when requested.
      Validate( doc1, ValidationType::XDR ); //Validation should fail.
      Validate( doc2, ValidationType::DTD ); //Validation should fail.
      Validate( doc3, ValidationType::None ); //No validation performed.
   }


private:
   void Validate( String^ filename, ValidationType vt )
   {
      try
      {
         
         //Implement the readers.  Set the ValidationType.
         txtreader = gcnew XmlTextReader( filename );
         reader = gcnew XmlValidatingReader( txtreader );
         reader->ValidationType = vt;
         
         //If the reader is set to validate, set the event handler.
         if ( vt == ValidationType::None )
                  Console::WriteLine( "\nParsing XML file {0}", filename
 );
         else
         {
            Console::WriteLine( "\nValidating XML file {0}", filename );
            m_success = true;
            
            //Set the validation event handler.
            reader->ValidationEventHandler += gcnew ValidationEventHandler( this,
 &Sample::ValidationCallBack );
         }
         
         // Read XML data
         while ( reader->Read() )
         {}
         if ( vt == ValidationType::None )
                  Console::WriteLine( "Finished parsing file." );
         else
                  Console::WriteLine( "Validation finished. Validation {0}",
 m_success ? (String^)"successful" : "failed" );
      }
      finally
      {
         
         //Close the reader.
         if ( reader != nullptr )
                  reader->Close();
      }

   }


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

};

int main()
{
   gcnew Sample;
}

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Schema.*;

public class Sample
{
    private String doc1 = "notValid.xml";
    private String doc2 = "cdDTD.xml";
    private String doc3 = "book1.xml";
    private XmlTextReader txtReader = null;
    private XmlValidatingReader reader = null;
    private boolean mSuccess = true;

    public Sample()
    {
        //Parse the files and validate when requested.
        Validate(doc1, ValidationType.XDR); //Validation should fail.
        Validate(doc2, ValidationType.DTD); //Validation should fail.
        Validate(doc3, ValidationType.None); //No validation performed.
    } //Sample

    public static void main(String[]
 args)
    {
        Sample validation =  new Sample();
    } //main

    private void Validate(String fileName,
 ValidationType vt)
    {
        try {
            //Implement the readers.  Set the ValidationType.
            txtReader = new XmlTextReader(fileName);
            reader = new XmlValidatingReader(txtReader);
            reader.set_ValidationType(vt);

            //If the reader is set to validate, set the event handler.
            if (vt.Equals(ValidationType.None)) {
                Console.WriteLine("\nParsing XML file " 
                    + fileName.ToString());
            }
            else {
                Console.WriteLine("\nValidating XML file " 
                    + fileName.ToString());
                mSuccess = true;

                //Set the validation event handler.
                reader.add_ValidationEventHandler(new ValidationEventHandler
                    (ValidationCallBack));
            }
            // Read XML data
            while(reader.Read()) {

            } 
            if ( vt.Equals(ValidationType.None)) {
                Console.WriteLine("Finished parsing file.");
            }
            else {
                Console.WriteLine("Validation finished. Validation {0}"
,
                    (mSuccess == true) ? "successful"
 : "failed");
            }
        } 
        finally {
            //Close the reader.
            if (reader != null) {
                reader.Close();
            }
        }
    } //Validate

    //Display the validation errors.
    private void ValidationCallBack(Object
 sender, ValidationEventArgs args) 
    {
        mSuccess = false;
        Console.Write("\r\n\tValidation error: " + args.get_Message());
    } //ValidationCallBack 
} //Sample

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

notValid.xml ("x-schema:" プレフィックスは、リーダーXML-Data Redued (XDR) スキーマ識別します)

<?xml version='1.0'?>
<bookstore xmlns="x-schema:schema1.xdr">
  <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>

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>

cdDTD.xml

<!--XML file using a DTD-->
<!DOCTYPE bookstore [
  <!ELEMENT bookstore (cd)*>
 
  <!ELEMENT cd (title,artist,price)>
  <!ATTLIST cd genre CDATA #REQUIRED>
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT artist (#PCDATA)>
  <!ELEMENT price (#PCDATA)>]>
<bookstore>
  <cd genre="alternative"  ISBN="2-3631-4">
    <title>Americana</title>
    <artist>Offspring</artist>
    <price>16.95</price>
  </cd>
</bookstore>

book1.xml

<?xml version='1.0' ?>
<!DOCTYPE book [<!ENTITY
 h 'hardcover'>]>
<book>
  <title>Pride And
 Prejudice</title>
  <misc>&h;</misc>
</book>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS