2016-07-20 11 views
0

私はContactNumberという親要素を必須としています。必須要素ではない4つの子要素(モバイル、仕事、ファックス、家庭)があります。これらの4人の子供のいずれかからの親。どのようにすればいいですか?親要素は必須xmlの子要素ではありません

<xs:element name="contactDetails"> 
    <xs:complexType> 
    <xs:element name="jobTitle" /> 
    <xs:sequence><xs:element name="contactNumber" type="contactNumberInfo" minOccurs="1" maxOccurs="3" />   
    </xs:sequence> 
</xs:complexType> 
    </xs:element> 
<xs:complexType name="contactNumberInfo"> 
    <xs:sequence> 
     <xs:element name="mobile"> 
      <xs:simpleType> 
       <xs:restriction base="xs:positiveInteger"> 
        <xs:pattern value="[0-9]{10}" /> 
       </xs:restriction> 
      </xs:simpleType> 
     </xs:element>   

     <xs:element name="home" type="xs:positiveInteger" /> 
     <xs:element name="work" type="xs:positiveInteger" /> 
     <xs:element name="fax" type="xs:positiveInteger" /> 
    </xs:sequence> 
</xs:complexType> 

答えて

1

要素の固定されたシーケンスがある場合は、XML schema construct for "any one or more of these elements but must be at least one"に似ています。

試してみてください。

<xs:element name="ContactNumber"> 
     <xs:complexType> 
      <xs:choice> 
       <xs:sequence> 
        <xs:element name="home" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" /> 
        <xs:element name="work" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
        <xs:element name="fax" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
        <xs:element name="mobile" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
       </xs:sequence> 
       <xs:sequence> 
        <xs:element name="work" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" /> 
        <xs:element name="fax" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
        <xs:element name="mobile" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
       </xs:sequence> 
       <xs:sequence> 
        <xs:element name="fax" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" /> 
        <xs:element name="mobile" type="xs:positiveInteger" minOccurs="0" maxOccurs="1" /> 
       </xs:sequence> 
       <xs:sequence> 
        <xs:element name="mobile" type="xs:positiveInteger" minOccurs="1" maxOccurs="1" /> 
       </xs:sequence> 
      </xs:choice> 
     </xs:complexType> 
    </xs:element> 
関連する問題