2012-07-09 37 views
0

如何禁止我的xml文件中限制標記中的重複標記? 例如在我的XML文件我有兩個區域的標籤,但它應該是隻有一個標籤如何讓標籤兒童獨特?

這是我的xml文件:

<app:string name="firstName"> 
     <app:restriction> 
      <app:regex>^\w*$</app:regex> 
      <app:type/> 
      <app:locale/> 
      <app:locale/> 
     </app:restriction> 
    </app:string> 

,這是我的字符串標記的xsd:

<xs:element name="string"> 
    <xs:complexType> 
     <xs:complexContent> 
      <xs:extension base="main:BaseType"> 
       <xs:sequence> 
        <xs:element name="restriction" type="main:StringRestriction" minOccurs="0" 
           maxOccurs="1"/> 
       </xs:sequence> 
       <xs:attribute name="lang" type="main:LocaleTypes"/> 
      </xs:extension> 
     </xs:complexContent> 
    </xs:complexType> 
</xs:element> 

<xs:complexType name="BaseType"> 
    <xs:attribute name="name" type="main:nameType" use="required"/> 
    <xs:attribute name="readonly" type="xs:boolean" use="optional" default="true"/> 
</xs:complexType> 

<xs:complexType name="StringRestriction"> 
    <xs:complexContent> 
     <xs:extension base="main:RestrictionBase"> 
      <xs:sequence> 
       <xs:choice maxOccurs="1"> 
        <xs:element type="xs:string" name="locale"/> 
        <xs:element type="xs:string" name="type"/> 
        <xs:element type="xs:string" name="regex"/> 
        <xs:element type="xs:string" name="maxLen"/> 
        <xs:element type="xs:string" name="minLen"/> 
       </xs:choice> 
      </xs:sequence> 
     </xs:extension> 
    </xs:complexContent> 
</xs:complexType> 

回答

1

如果我正確理解你需要一個模式,強制你的restriction標籤包含標籤沒有重複。

如果替代這次

<xs:sequence> 
    <xs:choice maxOccurs="1"> 
     <xs:element type="xs:string" name="locale"/> 
     <xs:element type="xs:string" name="type"/> 
     <xs:element type="xs:string" name="regex"/> 
     <xs:element type="xs:string" name="maxLen"/> 
     <xs:element type="xs:string" name="minLen"/> 
    </xs:choice> 
</xs:sequence> 

與此:

<xs:all minOccurs="0"> 
    <xs:element type="xs:string" name="locale"/> 
    <xs:element type="xs:string" name="type"/> 
    <xs:element type="xs:string" name="regex"/> 
    <xs:element type="xs:string" name="maxLen"/> 
    <xs:element type="xs:string" name="minLen"/> 
</xs:all> 

您的架構不允許重複你的restriction標籤內locale元素。 你可以在這裏看到一個總結:http://www.w3schools.com/schema/el_all.asp 除此之外,你可以玩minOccursmaxOccurs強制一些elementes總是出現,其他只是可選的。

+0

是的,但順序的項目應該順序出現。 – Pooya 2012-07-09 17:53:24

+1

序列是一個排序列表,但我需要一個未排序的list.so,我使用的序列與選擇 – Pooya 2012-07-09 17:54:21

+1

在這種情況下,您可以用xsd:all元素替換xsd:sequence元素。 xsd:all指定子元素可以以任何順序出現,並且每個子元素可以出現零次或一次。 – user1187008 2012-07-10 07:46:41