Share via


AttributeGroup 요소의 바인딩 지원

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

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

XML 스키마 문서에서 소스 코드를 생성할 경우 Xsd.exe는 각 <attributeGroup> 참조를 해당 참조가 들어 있는 <complexType> 정의와 일치하는 클래스로 직접 확장합니다.

설명

<attributeGroup> 요소를 사용하면 스키마 디자이너에서 특성 그룹을 전역으로 정의한 다음 여러 복합 형식에서 참조를 통해 이 그룹을 다시 사용할 수 있습니다.

.NET Framework에는 특성 그룹을 코드에 표시하기 위한 관용구가 없습니다. 대신 XML 스키마 문서에서 소스 코드를 생성할 때 Xsd.exe는 ref 특성을 통해 각 <attributeGroup> 참조를 해당 참조가 들어 있는 <complexType> 정의와 일치하는 클래스로 직접 확장합니다. 각 특성에 대해 public 필드가 생성됩니다. 각 public 필드에는 XmlAttributeAttribute 특성이 표시되며, 이 특성은 약식 이름 XmlAttribute로 나타낼 수도 있습니다.

개발자가 동일한 특성 바인딩 필드 또는 속성의 그룹을 여러 클래스에 직접 정의하지 않으려는 경우, 기본 클래스를 수동으로 만들고 XML 스키마 복합 형식을 나타내는 클래스가 이 기본 클래스에서 상속되도록 할 수 있습니다. 각 public 필드나 속성에는 XmlAttribute 특성이 있어야 합니다. 그렇지 않으면 이 필드나 속성은 특성이 아닌 복합 형식의 요소로 해석됩니다.

Example

입력 XML 스키마 문서:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns="http://example.org/" targetNamespace="http://example.org/" elementFormDefault="qualified">
    <xsd:attributeGroup name="version">
      <xsd:attribute name="changeNumber" type="xsd:int" use="required"/>
      <xsd:attribute name="instanceId" type="xsd:string" use="required"/>
    </xsd:attributeGroup>
    <xsd:complexType name="keyInfo">
      <xsd:sequence>
        <xsd:element name="key" type="xsd:string"/>
      </xsd:sequence>
      <xsd:attributeGroup ref="version" />
    </xsd:complexType>
    <xsd:element name="key" type="keyInfo"/>
</xsd:schema>

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

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute("key", Namespace="http://example.org/", IsNullable=false)]
public class keyInfo {
        
    public string key;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public int changeNumber;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string instanceId;
}

앞의 C# 소스에서 컴파일된 어셈블리에서 생성된 XML 스키마 복합 형식:

<xs:schema xmlns:tns="http://example.org/" elementFormDefault="qualified" targetNamespace="http://example.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="key" type="tns:keyInfo" />
  <xs:complexType name="keyInfo">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="key" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="changeNumber" type="xs:int" />
    <xs:attribute name="instanceId" type="xs:string" />
  </xs:complexType>
</xs:schema>

가능한 특성 바인딩 지원

id

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

name

Xsd.exe 유틸리티는 <attributeGroup> 요소의 콘텐츠를 익명으로 확장하므로, 특성 그룹 이름을 무시합니다.

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

ref

.NET Framework에는 특성 그룹을 코드에 표시하기 위한 관용구가 없습니다. 대신, XML 스키마 문서에서 소스 코드를 생성할 때 Xsd.exe에서는 전역으로 선언된 특성 그룹에 대한 각 ref 특성의 <attributeGroup> 참조를 참조가 포함된 <complexType> 정의에 해당하는 클래스로 확장합니다. <attributeGroup>의 각 특성에 대해 System.Xml.Serialization.XmlAttributeAttribute 특성을 가진 public 필드가 생성되며, 이 특성은 약식 이름인 XmlAttribute로도 표시될 수 있습니다.

가능한 부모 요소: <attributeGroup>, <complexType>, <extension>, <redefine>, <restriction>, <schema>

가능한 자식 요소: <annotation>, <anyAttribute>, <attribute>, <attributeGroup>

참고 항목

참조

XmlSchemaAttributeGroup
XmlSchemaAttributeGroupRef