XmlReaderSettings.ValidationType XmlReaderSettings.ValidationType XmlReaderSettings.ValidationType XmlReaderSettings.ValidationType Property

정의

XmlReader가 읽는 동안 유효성 검사 또는 형식 할당을 수행할지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the XmlReader will perform validation or type assignment when reading.

public:
 property System::Xml::ValidationType ValidationType { System::Xml::ValidationType get(); void set(System::Xml::ValidationType value); };
public System.Xml.ValidationType ValidationType { get; set; }
member this.ValidationType : System.Xml.ValidationType with get, set
Public Property ValidationType As ValidationType

속성 값

XmlReader가 판독 시 유효성 검사나 형식 할당을 수행하는지 여부를 나타내는 ValidationType 값 중 하나입니다.One of the ValidationType values that indicates whether XmlReader will perform validation or type assignment when reading. 기본값은 ValidationType.None입니다.The default is ValidationType.None.

예제

다음 예제에서 저장 된 스키마를 사용 하 여 유효성을 검사 합니다 XmlSchemaSet합니다.The following example validates using a schema stored in the XmlSchemaSet.

#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:\n   {0}", e->Message );
   Console::WriteLine();
}

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;
}
// The example displays output like the following:
//   Validation Error: 
//        The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author' 
//        in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in 
//        namespace 'urn:bookstore-schema'.
//
//    Validation Error: 
//       The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name' 
//       in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in 
//       namespace 'urn:bookstore-schema'.
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 += 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:\n   {e.Message}\n");
  }
}
// The example displays output like the following:
//   Validation Error: 
//        The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author' 
//        in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in 
//        namespace 'urn:bookstore-schema'.
//
//    Validation Error: 
//       The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name' 
//       in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in 
//       namespace 'urn:bookstore-schema'.
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO

Public Module Sample 
  Public 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 Sub ValidationCallBack(sender as object, e as ValidationEventArgs) 
    Console.WriteLine($"Validation Error:{vbCrLf}   {e.Message}")
    Console.WriteLine()
  End Sub
End Module
' The example displays output like the following:
'   Validation Error: 
'        The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author' 
'        in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in 
'        namespace 'urn:bookstore-schema'.
'
'    Validation Error: 
'       The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name' 
'       in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in 
'       namespace 'urn:bookstore-schema'.

이 샘플에서는 다음 입력된 파일 사용:The sample uses the following input files:

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>

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>

설명

다음 표에서 ValidationType 값입니다.The following table describes the ValidationType values.

참고

합니다 AutoXDR 열거형 값은.NET Framework 버전 2.0에서에서 사용 되지 않습니다.The Auto and XDR enumeration values are obsolete in .NET Framework version 2.0.

ValidationTypeValidationType 설명Description
DTD 유효성 검사는 문서 형식 정의 (DTD)를 사용 하 여 수행 됩니다.Validation is performed using a document type definition (DTD). 참고: DtdProcessing 속성도 로Parse설정 해야 합니다.Note: The DtdProcessing property must also be set to Parse.
None XmlReader 모든 형식 할당을 수행 하거나 데이터의 유효성을 검사 하지 않습니다.The XmlReader does not validate data, or perform any type assignment.
Schema 유효성 검사 및 형식 할당은 XML 스키마 정의 언어 (XSD) 스키마를 사용 하 여 수행 됩니다.Validation and type assignment is performed using an XML Schema definition language (XSD) schema. 판독기는 다음을 사용 하 여 XML 스키마에 액세스 합니다.The reader accesses the XML Schema using the following:

-사용 된 Schemas 속성에 액세스를 XmlSchemaSet 이 판독기와 연결 된 개체입니다.- Uses the Schemas property to access the XmlSchemaSet object associated with this reader.
-XML 인스턴스 문서에 포함 된 인라인 스키마를 사용 합니다.- Uses the in-line schema contained in the XML instance document. (의 ProcessInlineSchema 옵션이 설정 되어야 합니다.)(The ProcessInlineSchema option must be enabled.)
--스키마 위치 힌트에서 지정한 XML 스키마를 사용 하는 중 (xsi:schemaLocation 또는 xsi:noNamespaceSchemaLocation 특성) XML 인스턴스 문서에서 찾을 수 있습니다.- Uses the XML Schema specified by schema location hints (xsi:schemaLocation or xsi:noNamespaceSchemaLocation attribute) found in the XML instance document. (의 ProcessSchemaLocation 옵션이 설정 되어야 합니다.)(The ProcessSchemaLocation option must be enabled.)

적용 대상

추가 정보