2009-10-08 2 views
3

을 나는 XML의 다음과 같은 부분이이 XSD에서제한 또는 XSI에 사용되는 값 제한 : type 속성

<MyField> 
    <FieldName>Blah</FieldName> 
    <ValueFormatting xsi:type="DateFormatter"> 
     <Format>dd/MM/yy</Format> 
    </ValueFormatting> 
</MyField> 

, 내가 제한하거나 xsi:type가 속성에 대해 제공되는 값을 제한 할 수있는 방법을 ValueFormatting 요소 (예 : TextFormatter, NumberFormatter, DateFormatter 등)가 유효한 네 가지 또는 다섯 가지 유형의 목록이 있습니까?

내 XSD에서 속성 이름이 "xsi : type"임을 어떻게 강요 할 수 있습니까? 대신에 "type"이라는 속성 이름을 가지고 도망 갈 수는 있지만, "type"이 다른 네임 스페이스에 선언되면 충돌을 일으킬 수 있습니다.

감사합니다.

답변

3

"type"속성의 허용되는 값을 제한하려면 "type"속성의 XSD 정의에서 태그를 사용하십시오.

속성 이름 자체에 대해 XML은 주어진 접두사를 사용하는 네임 스페이스 (기본값 또는 기타)를 정의해야하며 XSD는 "유형"속성의 "targetNamespace"특성에서 동일한 네임 스페이스를 지정해야합니다. 속성의 정의. XML에 "xsi"접두사를 사용하도록 강제 할 수는 없습니다. 실제로 접두사 "xsi"는 예약되어 있지만 XML이 "type"속성을 사용하는지 확인하기 위해 네임 스페이스가 가리키는 곳을 강제로 지정할 수 있습니다 다른 사람이 아니라 예를 들어

은 :

<xsd:element name="ValueFormatting"> 
    <xsd:complexType> 
    <xsd:attribute name="type" minOccurs="1" maxOccurs="1" targetNamespace="http://..."> 
     <xsd:simpleType> 
     <xsd:restriction base="xsd:string"> 
      <xsd:enumeration value="TextFormatter" /> 
      <xsd:enumeration value="NumberFormatter" /> 
      <xsd:enumeration value="DateFormatter" /> 
     </xsd:restriction> 
     </xsd:simpleType> 
    </xsd:attribute> 
    ... 
    </xsd:complexType> 
</xsd:element> 

<MyField> 
    <FieldName>Blah</FieldName> 
    <ValueFormatting xmlns:myns="http://..." myns:type="DateFormatter"> 
     <Format>dd/MM/yy</Format> 
    </ValueFormatting> 
</MyField> 
+1

어떻게 작동하도록되어? 'targetNamespace' 속성은'xs : attribte'에 없습니다. –

+1

당시 XML 스키마 스펙 (http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#cAttribute_Declarations)을 읽은 것처럼 보였습니다. 다시 읽으면'xs : attribute'가 상위'schema'에서'targetNamespace'를 상속받은 것처럼 보입니다. –

+0

설명해 주셔서 감사합니다. 이것을 시도 할 것이다. –