How can i define an boolean attribute that can be set "true" only in one element. Following snippet must be invalid.
<products>
<product featured="yes">Prod 1</product>
<product featured="yes">Prod 2</product>
</products>
How can i define an boolean attribute that can be set "true" only in one element. Following snippet must be invalid.
<products>
<product featured="yes">Prod 1</product>
<product featured="yes">Prod 2</product>
</products>
You can't do that with XML Schemas.
You can define attributes on an element, but not limit them to one instance of the element.
You could add an attribute in products
element indicating which product
is featured.
You can't do this with XMLSchema. If you want to specify these constraints in an XML environment try Schematron (http://www.schematron.com/).
My reply is this way, 'cause I cannot add comments yet.
"You could add an attribute in products element indicating which product is featured."
This solution lead to another problem: checking if the attribute points to existing element.
<products featured_id="3">
<product id="1">Prod 1</product>
<product id="2">Prod 2</product>
</products>