Tom
Tom

Reputation:

XML Schema: Make the value of a multiple occuring tag unique

I have this XML pattern...

<module>
   <promo>
      <day>1</day>
      <day>2</day>
   </promo>
   <promo>
      <day>3</day>
      <day>4</day>
   </promo>
   <promo>
      <day>Default</day>
   </promo>
</module>

I would like to stop users putting the same value into 2 <day> tags anywhere in the <module> tag.

I can currently do it using the <xsd:unique> tag, but this doesn't allow me to have two <day> tags in one <promo> tag.

I could also use the attribute base="xs:ID" but this doesn't allow the value to start with a number.

Any help is much appreciated.

Regards, Tom.

Upvotes: 2

Views: 1738

Answers (1)

Tom
Tom

Reputation:

Here is the answer to my question. Setting a xs:unique tag to this...

<xsd:unique name="day">
    <xs:selector xpath="promo/day" />
    <xs:field xpath="." />
</xsd:unique>

In the element declaration for the 'module' tag gives me the functionality I need.

Regards, Tom.

Upvotes: 6

Related Questions