문제
나는 당신의 도움이 필요하를 정의하는 특별한 경우에는 XML 스키마에시퀀스를 포함하는 두 가지 요소:'x'과'y'반면:
<x>
요소를 나타날 수 있습 0 하여 약속 안함 시간 순서<y>
요소를 나타날 수 있습 0~1 시간 순서<x>
고<y>
위치가 어디 에나있을 수 있습니다-그것은,그것이 가능하여 약속 안함 시간<x>
요소와 그 단일<y>
요소이며,그 약속 안함 시간<x>
요소입니다.
XML 의 예에는 이 문제는:
Example#1
<x>stuff</x>
<y>stuff</y>
<x>stuff</x>
Example#2
<y>stuff</y>
<x>stuff</x>
<x>stuff</x>
Example#3
<x>stuff</x>
<x>stuff</x>
<y>stuff</y>
<x>stuff</x>
감사합니다!
해결책
여러 가지 이유로 Yuval 's, Mo's 또는 Davidsheldon의 샘플이 작동하지 않습니다. 여기에 있습니다.
<xs:complexType name="myComplexType">
<xs:sequence>
<xs:element name="x" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:sequence minOccurs="0">
<xs:element name="y" type="xs:string"/>
<xs:element name="x" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:sequence>
</xs:complexType>
다른 팁
편집:로 Alohci 언급한 내 솔루션은 잘못된 것입니다.에 따라 사양에서 요소 xs:모든 나타날 수 있 하나 이 시간입니다.이 숙박 시설에는 흡연 구역이 지정
나는 당신이 원하는 것을 생각지 않습니다.시퀀스가 정의되지만 요소뿐만 아니라입니다.고 당신의 경우에는 순서가 변경될 수 있습니다.을 시도했다 xs:니까?
<xs:complexType name="myComplexType">
<xs:all>
<xs:element name="x" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="y" type="xs:string" maxOccurs="1"/>
</xs:all>
</xs:complexType>
다른 appraoch 될 수 있을 만들기 시퀀스지 표시 순서 maxOccurs="unbounded"
그것은 이후 잠시되었습니다 내가 사용되는 스키마에,그러나 내가 생각하는 시퀀스가 여기에 대답.
필요하며 무제한 숫자의 선택 사이에(x)또는(y 다음 x)
<xsd:element name="parent">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="x" type="xs:string"/>
<xsd:sequence>
<xsd:element name="y" type="xsd:string" />
<xsd:element name="x" type="xsd:string" />
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
</xsd:element>
너무 복잡하지 않습니다. 내 머리 꼭대기에서 그것은 다음과 같아야합니다.
<xs:element name="x" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="y" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="x" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
XSD의 각 요소는 기본적으로 선택 사항 이므로이 XSD는 정의 한 XML 구조와 일치합니다. y
요소는 전, 후 또는 사이에 어디서나 나타납니다 x
최대 발생이 1의 요소