2012-04-27 5 views

답변

3

느슨한 maxOccurs="3"와 당신이 가지고하는 것은 "선택 적어도 하나", 아니 반복이다.

입자의 경우 기본값은 입니다. 각 옵션 입자 자체가 필수 항목 인 필수 선택 사항이 사용자의 대답입니다.

업데이트 : 귀하의 의견을 토대로, 설명하신 입자의 조합을 주문한 것이라면 XSD 사양으로 얻을 수있는 최상의 방법입니다.

<?xml version="1.0" encoding="utf-8" ?> 
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="root"> 
     <xsd:complexType> 
      <xsd:choice> 
       <xsd:sequence> 
        <xsd:element ref="c1"/> 
        <xsd:element ref="c2" minOccurs="0"/> 
        <xsd:element ref="c3" minOccurs="0"/> 
       </xsd:sequence> 
       <xsd:sequence> 
        <xsd:element ref="c2"/> 
        <xsd:element ref="c3" minOccurs="0"/> 
       </xsd:sequence> 
       <xsd:element ref="c3"/> 
      </xsd:choice> 
     </xsd:complexType> 
    </xsd:element> 
    <xsd:element name="c1" type="xsd:string"/> 
    <xsd:element name="c2" type="xsd:string"/> 
    <xsd:element name="c3" type="xsd:string"/> 
</xsd:schema> 

이미 지저분합니다. 더 많은 수의 입자 또는 정렬되지 않은 조합을 찾고 있다면이 모델을 다음과 같이 변경할 것입니다 (XSD 1.0 제한 사항 - 모든 것은 XPath 구문의 제한 사항과 관련이 있습니다. 선택기/필드).

<?xml version="1.0" encoding="utf-8" ?> 
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="root"> 
     <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element ref="c" maxOccurs="unbounded"/> 
      </xsd:sequence> 
     </xsd:complexType> 
     <xsd:key name="pk"> 
      <xsd:selector xpath="*"/> 
      <xsd:field xpath="@code"/> 
     </xsd:key> 
    </xsd:element> 
    <xsd:element name="c" type="TC" abstract="true"/> 
    <xsd:element name="c1" type="TC1" substitutionGroup="c"/> 
    <xsd:element name="c2" type="TC2" substitutionGroup="c"/> 
    <xsd:element name="c3" type="TC3" substitutionGroup="c"/> 

    <xsd:complexType name="TC"> 
     <xsd:simpleContent> 
      <xsd:extension base="xsd:string"> 
       <xsd:attribute name="code" type="xsd:string"/> 
      </xsd:extension> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC1"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c1"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC2"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c2"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC3"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c3"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
</xsd:schema> 

샘플 XML이 좋아하는 것 :

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <c1 code="c1">c11</c1> 
    <c2 code="c2">c21</c2> 
    <c3 code="c3">c21</c3> 
</root> 

나이 :

기본적으로 당신이 그의 일부입니다, 당신의 요소가 특별하게 만드는 몇 가지 요소에 키 입력하고
<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <c2 code="c2">c21</c2> 
    <c1 code="c1">c11</c1> 
</root> 

태그 이름과 반대되는 데이터. 다시 말하지만, 지저분한 운동이지만, 당신에게 아이디어를 줄 수 있습니다.

+0

maxOccurs를 없애면 둘 이상의 것을 선택할 수 없습니다. "임대 중 하나"란 (c1) 또는 (c1 및 c2 및 c3) 또는 (c2 및 c3) 등의 의미입니다. –