David
David

Reputation: 965

Difference between 2 simple DTD declarations

Could someone explain the difference between the following DTD statements?

<!ELEMENT all (book+, dvd+)>

and

<!ELEMENT all (book, dvd)+>

Upvotes: 0

Views: 121

Answers (2)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25034

The content model (book+, dvd+) matches a sequence of elements: first, one or more book elements (that's book+), then (that's ,) one or more dvd elements (that's dvd+). So the following match this content model:

  1. <book/><dvd/>
  2. <book/><book/><book/><dvd/>
  3. <book/><dvd/><dvd/><dvd/><dvd/><dvd/>
  4. <book/><book/><book/><book/><dvd/><dvd/>

etc.

The content model (book, dvd)+ matches one or more occurrences of the sequence consisting of one book followed by one dvd. So the following match it:

  1. <book/><dvd/>
  2. <book/><dvd/><book/><dvd/>
  3. <book/><dvd/><book/><dvd/><book/><dvd/>
  4. <book/><dvd/><book/><dvd/><book/><dvd/><book/><dvd/>

etc.

The difference is that in the first expression, the two + operators apply to the individual element names book and dvd; in the second, the + applies to the sequence (book, dvd) as a whole.

Note that the first example in each list is legal under both content models, and that none of the others are.

Upvotes: 1

nl-x
nl-x

Reputation: 11832

With 0 knowledge of dtd's:

I'd say the first one should contain at least 1 book AND 1 dvd. But may contain many books and/or dvd's.

The second one contains should contain at least 1 book OR 1 dvd. But may contain many books and/or dvd's.

Upvotes: 0

Related Questions