XmlValidatingReader.SchemaType 속성

정의

스키마 형식 개체를 가져옵니다.

public:
 property System::Object ^ SchemaType { System::Object ^ get(); };
public object? SchemaType { get; }
public object SchemaType { get; }
member this.SchemaType : obj
Public ReadOnly Property SchemaType As Object

속성 값

Object

노드 값이 기본 제공 XSD(XML 스키마 정의 언어) 형식인지 사용자 정의 simpleType 또는 complexType인지 여부에 따라 XmlSchemaDatatype, XmlSchemaSimpleType 또는 XmlSchemaComplexType입니다. 현재 노드에 스키마 형식이 없으면 null입니다.

예제

다음은 XML 문서의 각 요소에 대한 형식 정보를 표시하는 예제입니다.

#using <System.Xml.dll>
#using <System.dll>

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

public ref class Sample
{
private:
   static void ValidationCallBack( Object^ sender, ValidationEventArgs^ args )
   {
      Console::WriteLine( "***Validation error" );
      Console::WriteLine( "\tSeverity: {0}", args->Severity );
      Console::WriteLine( "\tMessage  : {0}", args->Message );
   }

public:
   static void main()
   {
      XmlTextReader^ tr = gcnew XmlTextReader( "booksSchema.xml" );
      XmlValidatingReader^ vr = gcnew XmlValidatingReader( tr );
      vr->Schemas->Add( nullptr, "books.xsd" );
      vr->ValidationType = ValidationType::Schema;
      vr->ValidationEventHandler += gcnew ValidationEventHandler( Sample::ValidationCallBack );
      while ( vr->Read() )
      {
         if ( vr->NodeType == XmlNodeType::Element )
         {
            if ( dynamic_cast<XmlSchemaComplexType^>(vr->SchemaType) != nullptr )
            {
               XmlSchemaComplexType^ sct = dynamic_cast<XmlSchemaComplexType^>(vr->SchemaType);
               Console::WriteLine( " {0}( {1})", vr->Name, sct->Name );
            }
            else
            {
               Object^ value = vr->ReadTypedValue();
               Console::WriteLine( " {0}( {1}): {2}", vr->Name, value->GetType()->Name, value );
            }
         }
      }
   }
};

int main()
{
   Sample::main();
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Sample{

  public static void Main(){

  XmlTextReader tr = new XmlTextReader("booksSchema.xml");
  XmlValidatingReader vr = new XmlValidatingReader(tr);

  vr.Schemas.Add(null, "books.xsd");
  vr.ValidationType = ValidationType.Schema;
  vr.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

  while(vr.Read()){
    if(vr.NodeType == XmlNodeType.Element){
      if(vr.SchemaType is XmlSchemaComplexType){
        XmlSchemaComplexType sct = (XmlSchemaComplexType)vr.SchemaType;
        Console.WriteLine("{0}({1})", vr.Name, sct.Name);
      }
      else{
        object value = vr.ReadTypedValue();
        Console.WriteLine("{0}({1}):{2}", vr.Name, value.GetType().Name, value);
      }
    }
  }
 }

  private static void ValidationCallBack (object sender, ValidationEventArgs args){
    Console.WriteLine("***Validation error");
    Console.WriteLine("\tSeverity:{0}", args.Severity);
    Console.WriteLine("\tMessage  :{0}", args.Message);
  }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema

public class Sample

  public shared sub Main()
  
  Dim tr as XmlTextReader = new XmlTextReader("booksSchema.xml")
  Dim vr as XmlValidatingReader = new XmlValidatingReader(tr)
 
  vr.Schemas.Add(nothing, "books.xsd")
  vr.ValidationType = ValidationType.Schema
  AddHandler vr.ValidationEventHandler, AddressOf ValidationCallBack

  while(vr.Read())

    if(vr.NodeType = XmlNodeType.Element)
    
      if (vr.SchemaType.ToString() = "System.Xml.Schema.XmlSchemaComplexType")
        Dim sct as XmlSchemaComplexType = CType(vr.SchemaType,XmlSchemaComplexType)
        Console.WriteLine("{0}({1})", vr.Name, sct.Name)
      else      
        Dim value as object = vr.ReadTypedValue()
        Console.WriteLine("{0}({1}):{2}", vr.Name, value.GetType().Name, value)    
      end if
    end if
  end while
  end sub

  private shared sub ValidationCallBack (sender as object, args as ValidationEventArgs)

   Console.WriteLine("***Validation error")
   Console.WriteLine("Severity:{0}", args.Severity)
   Console.WriteLine("Message  :{0}", args.Message)
  end sub
end class

이 예제에서는 다음 입력 파일을 사용합니다.

booksSchema.xml

<?xml version='1.0'?>
<bookstore xmlns="urn:bookstore-schema">
  <book genre="autobiography">
    <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">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.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>

설명

참고

클래스는 XmlValidatingReader .NET Framework 2.0에서 사용되지 않습니다. 클래스 및 Create 메서드를 사용하여 유효성 XmlReader 검사 인스턴스를 XmlReaderSettings 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

사용자는 반환된 형식을 테스트해야 합니다. 예를 들면 다음과 같습니다.

object obj = vreader.SchemaType;  
 if (obj is XmlSchemaType)  
 {  
   XmlSchemaType st = (XmlSchemaType)obj;  
   // use XmlSchemaType object  
 }  
 if (obj is XmlSchemaDatatype)  
 {  
   XmlSchemaDatatype sd = (XmlSchemaDatatype)obj;  
   Type vt = sd.ValueType;  
   // use XmlSchemaDatatype object  
       }  

XML 스키마 유효성 검사를 수행하는 XmlSchemaType 경우 읽는 현재 요소에 해당하거나 XmlSchemaDatatype 해당합니다. 문서 형식 정의(DTD 유효성 검사)를 수행하는 경우 이 속성은 반환됩니다 null.

XmlSchemaDatatype 현재 요소 또는 특성이 min 및 max와 같은 단순 형식에 대해 특수 유효성 검사 제약 조건을 지정할 수 있는 단순 형식인 경우 가 반환됩니다.

XmlSchemaSimpleType 는 현재 요소 또는 특성이 사용자 정의 simpleType인 경우 반환됩니다.

XmlSchemaComplexType 는 현재 요소가 사용자 정의 complexType인 경우 반환됩니다. 이 형식은 특성으로 반환할 수 없습니다.

참고

ValidationType.None으로 설정된 경우 ValidationType 스키마 또는 DTD에서 데이터 형식 정보가 제공되지 않습니다.

주의

호출 Close후 SchemaType은 Null을 반환합니다.

적용 대상

추가 정보