2016-11-29 6 views
1

location要素がXMLに含まれている場合、locationの子要素(localitywkt)のうちの少なくとも1つを指定するにはどうすればよいですか?XSD経由で少なくとも1つの子要素が存在することを確認するにはどうすればよいですか?

<xs:element name="location" nillable="true" minOccurs="0"> 
    <xs:complexType> 
    <xs:group ref="cs:locationGroup"></xs:group> 
    </xs:complexType> 
</xs:element> 

locationGroupの定義:

<xs:group name="locationGroup"> 
    <xs:all> 
    <xs:element name="locality" minOccurs="0"/> 
    <xs:element name="wkt" minOccurs="0"/> 
    </xs:all> 
</xs:group> 

私のXSDのバージョンは1.0です。可能な子要素のような少数のため

答えて

1

、単に許容組合せのxs:choice定義:このアプローチ

  • になる1つ又はlocality又はwktの両方を必要とすること

    <?xml version="1.0" encoding="utf-8"?> 
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    
        <xs:element name="location"> 
        <xs:complexType> 
         <xs:group ref="locationGroup"></xs:group> 
        </xs:complexType> 
        </xs:element> 
    
        <xs:group name="locationGroup"> 
        <xs:choice> 
         <xs:sequence> 
         <xs:element name="locality"/> 
         <xs:element name="wkt" minOccurs="0"/> 
         </xs:sequence> 
         <xs:sequence> 
         <xs:element name="wkt"/> 
         <xs:element name="locality" minOccurs="0"/> 
         </xs:sequence> 
        </xs:choice> 
        </xs:group> 
    </xs:schema> 
    

    注現在

  • は、両方が存在する場合に任意の順序を許可します。
  • は、XSD 1 .0(および1.1)

関連する問題