2009-09-09 5 views
0

나는 XML Schema element with attributes containing only text을 보았지만 그 대신에 xs : dateTime 요소가 있습니다. 문자열이 아닌 요소를 XML 스키마의 선택적 내용으로 선언하는 방법

문서

는이 같은 외모에 대한 스키마를 작성하려고 해요 :

<web-campaigns> 
    <web-campaign> 
    <id>1231</id> 
    <start-at nil="true"/> 
    </web-campaign> 
    <web-campaign> 
    <id>1232</id> 
    <start-at>2009-08-08T09:00:00Z</start-at> 
    </web-campaign> 
</web-campaigns> 

을 때때로 XS를 : 날짜 요소는 내용이, 때로는하지 않습니다. XS와 dateTime에 : 나는 XS를 교체 할 경우

<xs:element name="start-at"> 
    <xs:complexType mixed="true"> 
    <xs:simpleContent> 
     <xs:extension base="xs:dateTime"> 
     <xs:attribute name="nil" default="false" type="xs:boolean" use="optional" /> 
     </xs:extension> 
    </xs:simpleContent> 
    </xs:complexType> 
</xs:element> 

: 내가 지금까지 (아직 확인하지 않는)가 무엇

은 문자열이, 내가 잘 문서의 유효성을 검사 할 수 있습니다,하지만 난 정말 원하는 xs : dateTime : 소비자에게 해당 요소가 있음을 나타냅니다. 나는 mixed = "true"과 함께 사용하거나 아무렇지도 않게 시도했습니다. 당신은

<xs:element name="start-at" minOccurs="0"> 

혼합 모드 필요가 차이를 만드는 경우에, 나는 (맥 OS X 10.5) xmllint가와 XML Schema Validator

답변

1

를 사용하여 검증

사용자의 상황에 적합하지 않을, 당신은 돈 ' 그럴 필요가 없다. 기본적으로 , 즉 요소는 필수 항목입니다.

minOccurs = "0"인 경우 내용이있는 요소를 지정하거나 전혀 지정하지 않습니다. <start-at/>을 허용하려면 xs : dateTime을 사용할 수 없습니다.

3

사용자는 고유 한 유형을 유형의 통합으로 정의 할 수 있습니다.

1/전용 ""AHM 아무것도 할 수없는 문자열로 "빈"유형을 정의 :

<xs:simpleType name="empty"> 
    <xs:restriction base="xs:string"> 
    <xs:enumeration value=""/> 
    </xs:restriction> 
</xs:simpleType> 

2/다음 날짜 및 빈

<xs:simpleType name="empty-dateTime"> 
    <xs:union memberTypes="xs:dateTime empty"/> 
</xs:simpleType> 

3를 할 수있는 유형을 정의/모든 nullable datetime 요소를 type="empty-dateTime"

으로 선언하십시오.
관련 문제