Fixed 특성의 바인딩 지원

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

.NET Framework에서는 fixed 특성에 대한 바인딩 지원을 제공합니다.

설명

fixed 특성은 적합한 XML 문서에서 요소나 특성에 지정되어야 하는 상수 값을 설정하기 위해 <element> 또는 <attribute> 선언에 나타날 수 있습니다. 또한 이 특성은 <enumeration> 및 **<pattern>**을 제외한 제한 패싯 요소에도 나타날 수 있습니다. 이 경우 true 값을 지정하면 파생이 발생해도 관련 패싯 값이 변경되지 않습니다.

.NET Framework는 문자열 기반 열거형을 제외하고 데이터 형식 바인딩 또는 serialization에 대한 제한 패싯을 통합하지 않으므로 fixed 특성은 이 특성이 나타나는 패싯과 함께 무시됩니다. 스키마 개체 모델은 IsFixed 속성이 지정된 기본 XmlSchemaFacet 클래스를 제공합니다.

fixed 특성이 <element> 또는 <attribute> 요소에 나타나면 Xsd.exe는 다음 예제와 같이 필드를 기본값으로 정적으로 초기화합니다.

public int age = -1;

XML 스키마에 따르면 fixed 특성 값은 XML 스키마 단순 형식이어야 합니다. Xsd.exe에서 단순 형식에 대한 고정 값/기본값 변환 방법에 대한 자세한 내용은 default 특성을 참조하십시오.

요소 및 특성의 경우 스키마 개체 모델은 XmlSchemaAttributeXmlSchemaElement 클래스의 FixedValue 속성으로 fixed 특성을 나타냅니다.

Example

입력 XML 스키마 문서:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            targetNamespace="http://example.org/" xmlns="http://example.org/" elementFormDefault="qualified">
    <xsd:element name="FamilyDog" type="FamilyDogType"/>

    <xsd:complexType name="FamilyDogType">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string" fixed="Spot"/>
            <xsd:element name="birthdate" type="xsd:date" />
        </xsd:sequence>
        <xsd:attribute name="gender" type="GenderType" fixed="UNKNOWN"/>
        <xsd:attribute name="fixed" type="xsd:boolean" fixed="false"/>
        <xsd:attribute name="breed" type="xsd:string" fixed="Swedish Vallhund"/>
    </xsd:complexType>
    
    <xsd:simpleType name="GenderType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="FEMALE" />
            <xsd:enumeration value="MALE" />
            <xsd:enumeration value="UNKNOWN" />
        </xsd:restriction>
    </xsd:simpleType>
</xsd:schema>

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

[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
[System.Xml.Serialization.XmlRootAttribute("FamilyDog", Namespace="http://example.org/", IsNullable=false)]
 public class FamilyDogType {
        
     public string name = "Spot";
        
    [System.Xml.Serialization.XmlElementAttribute(DataType="date")]
    public System.DateTime birthdate;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public GenderType gender = GenderType.UNKNOWN;
        
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool genderSpecified;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public bool @fixed = false;
        
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool fixedSpecified;
        
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string breed = "Swedish Vallhund";
    
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://example.org/")]
public enum GenderType {        
    FEMALE,    
    MALE,
    UNKNOWN,
}

앞의 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="FamilyDog" type="tns:FamilyDogType" />
  <xs:complexType name="FamilyDogType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string" fixed="Spot"/>
      <xs:element minOccurs="1" maxOccurs="1" name="birthdate" type="xs:date" />
    </xs:sequence>
    <xs:attribute name="gender" type="tns:GenderType" />
    <xs:attribute name="fixed" type="xs:boolean" />
    <xs:attribute name="breed" type="xs:string" />
  </xs:complexType>
  <xs:simpleType name="GenderType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="FEMALE" />
      <xs:enumeration value="MALE" />
      <xs:enumeration value="UNKNOWN" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

포함할 수 있는 요소: <attribute>, <element>, 다양한 제한 패싯

참고 항목

참조

System.Xml.Schema.XmlSchemaAttribute.FixedValue
System.Xml.Schema.XmlSchemaElement.FixedValue
System.Xml.Schema.XmlSchemaFacet.IsFixed