You can do the following ...
<products> <product featured="Yes">Prod 1</product> <product>Prod 2</product> </products>
Then use a unique element to limit the attribute this way ...
<xs:unique name="UniqueFeaturedProduct"> <xs:selector xpath="product"/> <xs:field xpath="@featured"/> </xs:unique>
If you were to restrict the "featured" attribute to an optional enumeration of a single "Yes" value, then there can only be one attribute attribute. Something like that...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="products"> <xs:complexType> <xs:sequence> <xs:element name="product" type="productType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:unique name="UniqueFeaturedProduct"> <xs:selector xpath="product"/> <xs:field xpath="@featured"/> </xs:unique> </xs:element> <xs:simpleType name="featuredType"> <xs:restriction base="xs:string"> <xs:enumeration value="Yes"/> </xs:restriction> </xs:simpleType> <xs:complexType name="productType"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="featured" type="featuredType" use="optional"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:schema>
Objeron
source share