다음을 통해 공유


ComplexType 요소의 바인딩 지원

이 항목은 레거시 기술과 관련된 것입니다. 이제 XML Web services와 XML Web services 클라이언트는 다음을 사용하여 만들어야 합니다. Windows Communication Foundation.

.NET Framework에서는 <complexType> 요소에 대한 바인딩 지원을 제공합니다.

Xsd.exe 도구에서는 XML 스키마 복합 형식을, 복합 형식의 콘텐츠를 나타내는 public 필드나 속성을 가진 .NET Framework 형식과 동일한 것으로 간주합니다.

설명

Xsd.exe 도구에서는 XML 스키마 복합 형식을 복합 형식의 콘텐츠를 나타내는 공용 필드가 있는 .NET Framework 형식과 동일한 것으로 간주합니다.

Abstract 특성

추상 기본 형식의 인스턴스가 아닌 파생 형식의 인스턴스만 호환 XML 문서에 표시되도록 복합 형식이 abstract로 선언됩니다(abstract="true").

Xsd.exe에서는 추상 복합 형식을 추상 클래스와 동일한 것으로 간주합니다. 변환은 코드와 XSD 문서 간에 양방향으로 수행됩니다.

abstract 키워드가 사용된다는 점을 제외하고 추상 클래스는 비추상 기본 클래스와 동일하게 취급됩니다. 자식 클래스는 기본 클래스를 확장합니다. Xsd.exe는 추상 클래스의 각 하위 클래스마다 하나의 System.Xml.Serialization.XmlIncludeAttribute를 적용합니다. 각 XmlInclude 특성은 하위 클래스 형식을 지정합니다.

예제: Abstract 특성

다음 코드 예제에서는 <complexType> 요소에 abstract 특성을 사용하는 방법을 보여 줍니다 .

입력 XML 스키마 문서:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
         targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
  <xsd:element name="FamilyNode" type="FamilyNodeType" />
  <xsd:complexType name="FamilyNodeType">
    <xsd:sequence>
      <xsd:element name="Code" type="xsd:string" />
      <xsd:element name="Parent" type="Parent" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="Daughter">
    <xsd:complexContent>
      <xsd:extension base="Parent">
        <xsd:sequence>
          <xsd:element name="Date" type="xsd:dateTime" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="Son">
    <xsd:complexContent>
      <xsd:extension base="Parent">
        <xsd:sequence>
          <xsd:element name="Info" type="xsd:string" minOccurs="0"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="Parent" abstract="true">
    <xsd:sequence>
      <xsd:element name="Text" type="xsd:normalizedString" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="Grandchild">
    <xsd:complexContent>
      <xsd:extension base="Daughter">
        <xsd:attribute name="Parent" type="xsd:normalizedString" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:schema>

앞의 XML 스키마 문서에서 생성된 C# 클래스:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute("FamilyNode", Namespace="http://example.org/", IsNullable=false)]
public class FamilyNodeType {
        
    public string Code;
        
    public Parent Parent;
}
    
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Son))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Daughter))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Grandchild))]
public abstract class Parent {
    [System.Xml.Serialization.XmlElementAttribute(DataType="normalizedString")]
    public string Text;
}
    
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
public class Son : Parent {        
    public string Info;
}
    
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Grandchild))]
public class Daughter : Parent {
        
    public System.DateTime Date;
        
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool DateSpecified;
}
    
 [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
public class Grandchild : Daughter {        
    [System.Xml.Serialization.XmlAttributeAttribute("Parent", DataType="normalizedString")]
    public string Parent1;
}

앞의 C# 소스 코드에서 컴파일된 클래스에서 생성된 XML 스키마는 원래 C# 스키마와 사실상 동일합니다.

가능한 특성 바인딩 지원

abstract

Xsd.exe 유틸리티에서는 abstract="true"로 식별되는 추상 복합 형식을 추상 클래스와 동일한 것으로 간주합니다. Xsd.exe는 추상 클래스에서 상속되는 각 클래스에 대해 하위 클래스 형식을 지정하는 System.Xml.Serialization.XmlIncludeAttribute를 적용합니다.

앞에서 설명한 Abstract Attribute 단원을 참조하십시오.

block

block 특성을 데이터 형식에 적용하면 원래 형식이 지정된 경우 파생 형식이 원래 형식을 대체하지 못하도록 할 수 있습니다.

Xsd.exe 도구에서는 Schema 요소의 바인딩 지원 요소의 blockDefault 특성뿐 아니라 block 특성도 무시합니다.

final

final 특성을 데이터 형식에 적용하면 데이터 형식이 파생되지 못하도록 할 수 있습니다.

Xsd.exe에서는 <schema> 요소의 finalDefault 특성뿐 아니라 final 특성도 무시합니다.

id

Xsd.exe 유틸리티는 고유 식별자를 제공하기 위한 id 특성을 무시합니다. 대신 name 특성을 인식합니다.

mixed

mixed 특성을 참조하십시오.

name

name 특성 값은 Xsd.exe가 복합 형식에서 생성하는 .NET Framework 형식의 이름이 됩니다.

코딩 규칙을 따르기 위해 대/소문자 변경을 시도하지 않습니다. 예를 들어, <complexType> 요소의 name 특성 값이 testInfo인 경우 결과 클래스 이름은 첫 문자가 대문자인 TestInfo가 아닌 testInfo가 됩니다. 이름과 예약된 키워드가 충돌하면 이름 앞에 @ 기호가 붙습니다.

Xsd.exe는 클래스에서 <complexType> 정의를 생성할 때 클래스 이름을 name 특성 값에 사용합니다. TypeName 속성을 통해 다른 이름(name 특성 값)을 제공할 수도 있습니다.

Name 특성의 바인딩 지원 특성을 참조하십시오.

가능한 부모 요소: <element>, <redefine>, <schema>

가능한 자식 요소: <all>, <annotation>, <anyAttribute>, <attribute>, <attributeGroup>, <choice>, <complexContent>, <group>, <sequence>, <simpleContent>

참고 항목

참조

XmlSchemaComplexType