How to prohibit duplicate tag in my restriction tag in my xml file?
for example in my xml file I have two locale tag,but it should be only one tag
this is my xml file :
<app:string name="firstName">
<app:restriction>
<app:regex>^\w*$</app:regex>
<app:type/>
<app:locale/>
<app:locale/>
</app:restriction>
</app:string>
and this is my xsd for string tag:
<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>
If I correctly understood you need a schema that force your
restrictiontag to contain tags without repetitions.if you substitute this:
with this:
your schema won’t allow duplicated
localeelements inside yourrestrictiontag.You can see a summary here: http://www.w3schools.com/schema/el_all.asp
Beside this, you can play with
minOccursandmaxOccursto force some elementes to always appear and other to be just optional.