XmlReaderSettings.ValidationFlags 속성

정의

스키마 유효성 검사 설정을 나타내는 값을 가져오거나 설정합니다. 이 설정은 스키마(ValidationType.Schema로 설정된 ValidationType 속성) 유효성 검사를 하는 XmlReader 개체에 적용됩니다.

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

속성 값

유효성 검사 옵션을 지정하는 열거형 값의 비트 조합입니다. ProcessIdentityConstraintsAllowXmlAttributes는 기본적으로 사용되고 ProcessInlineSchema, ProcessSchemaLocationReportValidationWarnings는 기본적으로 사용되지 않습니다.

예제

다음 예제에서는 설정을 사용하도록 설정하여 인라인 XML 스키마에 대해 XML 파일의 유효성을 ProcessInlineSchema 검사합니다. XML 판독기는 유효성 검사 경고를 표시하도록 구성되었으므로 루트 요소에도 예상되는 경고가 표시됩니다.

using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class ValidXSD {

  public static void Main() {

    // Set the validation settings.
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
    settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
    settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

    // Create the XmlReader object.
    XmlReader reader = XmlReader.Create("inlineSchema.xml", settings);

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

  // Display any warnings or errors.
  private static void ValidationCallBack (object sender, ValidationEventArgs args) {
     if (args.Severity==XmlSeverityType.Warning)
       Console.WriteLine("\tWarning: Matching schema not found.  No validation occurred." + args.Message);
     else
        Console.WriteLine("\tValidation error: " + args.Message);
  }
}
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO

public class ValidXSD 

  public shared sub Main() 

    ' Set the validation settings.
    Dim settings as XmlReaderSettings = new XmlReaderSettings()
    settings.ValidationType = ValidationType.Schema
    settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ProcessInlineSchema
    settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings
      AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack

    ' Create the XmlReader object.
    Dim reader as XmlReader = XmlReader.Create("inlineSchema.xml", settings)

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

  ' Display any warnings or errors.
  private shared sub ValidationCallBack (sender as object, args as ValidationEventArgs)
     if (args.Severity=XmlSeverityType.Warning)
       Console.WriteLine("   Warning: Matching schema not found.  No validation occurred." + args.Message)
     else
        Console.WriteLine("   Validation error: " + args.Message)
     end if
  end sub 

end class

이 예제에서는 inlineSchema.xml 파일을 입력으로 사용합니다.

<root>
<!--Start of schema-->
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
            xmlns='xsdHeadCount'
            targetNamespace='xsdHeadCount'>
    <xs:element name='HeadCount'>
        <xs:complexType>
            <xs:sequence>
                <xs:element name='ID' type='xs:unsignedShort' maxOccurs='unbounded' />
            </xs:sequence>
            <xs:attribute name='division' type='xs:string' use='optional' default='QA'/>
        </xs:complexType>
    </xs:element>
</xs:schema>
<!--End of schema-->
<hc:HeadCount xmlns:hc='xsdHeadCount'>
    <ID>12365</ID>
    <ID>43295</ID>
    <division>Accounting</division>
</hc:HeadCount>
</root>

출력은 다음과 같습니다.

경고: 일치하는 스키마를 찾을 수 없습니다. 유효성 검사가 실행되지 않았습니다. 'root' 요소에 대한 스키마 정보를 찾을 수 없습니다.

유효성 검사 오류: 요소 'xsdHeadCount:HeadCount'에 잘못된 자식 요소 'division'이 있습니다. 'ID'가 있어야 합니다."

설명

중요

ProcessInlineSchema 개체의 ProcessSchemaLocationXmlReaderSettings 유효성 검사 플래그는 기본적으로 설정되지 않습니다. 이 플래그를 설정하면 XmlResolver 개체의 XmlReaderSettings를 사용하여 XmlReader에서 인스턴스 문서에 나타난 스키마 위치를 확인할 수 있습니다. 개체가 이 XmlResolver 면 및 ProcessSchemaLocation 유효성 검사 플래그가 설정된 경우에도 ProcessInlineSchema 스키마 위치가 확인되지 null않습니다.

문서의 유효성을 검사하는 동안 스키마를 추가하면 새 형식이 추가되고 해당 문서에 대한 유효성 검사 결과가 달라질 수 있습니다. 결과적으로 외부 스키마는 신뢰할 수 있는 소스에서만 확인해야 합니다.

문서의 많은 부분에 대해 ID 제약 조건이 있는 스키마에 대해 고가용성 시나리오에서 신뢰할 수 없는 대규모 XML 문서의 유효성을 검사할 때 플래그를 사용하지 않도록 ProcessIdentityConstraints 설정하는 것이 좋습니다(기본적으로 사용).

적용 대상

추가 정보