-1

i have a simple xml like this:

<whiskey>
    <taste></taste>
    <taste></taste>
</whiskey>

my problem is now that the user is only allowed to insert some DIFFERENT tastes --> how can i make sure with the DTD file that the user can only type in some 2 different vavalues and not the same...?

Thanks for any help!

greetz

nbg15
  • 129
  • 1
  • 3
  • 11
  • my dtd looks like this at the moment: ---------- <!ELEMENT Whiskey(Taste, Taste+)> ------------- what means at least 2 Tastes, but also more are possible... but how can i make sure, that Taste1 and Taste2 are not the same? – nbg15 Jan 13 '17 at 16:19

1 Answers1

1

Using a DTD you cannot make sure that all elements have different values. In fact, you cannot do that with the most widely used XML type definition languages such as XML Schema or Relax NG.

However, there are type definition languages based on assertions, such as Schematron, where you can specify invariants that must be verified by the XML document. In Schematron these assertions are written using XPath.

jpleal
  • 161
  • 7
  • True that XSD cannot require that "all elements" have different values; not true that OP's requirement (all `taste` elements within a given `whiskey` element have different values) cannot be enforced by XSD. – C. M. Sperberg-McQueen Jan 25 '17 at 20:19
  • Could you please give an example of an XSD that validates documents where the content of 2 elements is different but does not validate them if they are equal? – jpleal Jan 26 '17 at 15:38
  • Sure; define whisky and taste as for this vocabulary, and add a uniqueness constraint scoped to the whisky element, pointing to the child taste elements. – C. M. Sperberg-McQueen Jan 26 '17 at 23:05