Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: httpwebwitch

Message Too Old, No Replies

elements with the same name, and DTD rules?

needing tips from a DTD whiz

     

httpwebwitch

7:14 pm on Jul 27, 2007 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'll make up a hypothetical example to keep the code concise.

I want to create a DTD that enforces the following rules:


<!-- this is OK. -->
<o>
<pet>
<dog>
<collar/>
</dog>
</pet>
</>

<!-- this is also OK -->
<o>
<hot>
<dog>
<meat/>
</dog>
</hot>
</o>

<!-- however I want to prevent this -->
<o>
<pet>
<dog>
<meat/>
</dog>
</pet>
</o>

<!-- this is also NOT OK -->
<o>
<hot>
<dog>
<collar/>
</dog>
</hot>
</o>

the DTD definition I have of "dog" lets either happen
<!ELEMENT dog (collar,meat)>

is there a technique in DTD that will prevent a hotdog from having a collar, and a pet dog from containing meat?

cmarshall

7:25 pm on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know DTD (but I will lay odds that it can do that. It is an enforcement mechanism).

I use XSD (schema) and schema can certainly do it.

httpwebwitch

1:05 pm on Jul 31, 2007 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



From my probing, seems like DTD doesn't do that kind of validation. "dog" is allowed within "hot" and "pet", but below that all "dog"s are alike, whether they're pets or food.

I'm using schema anyways now, to enforce some attribute values... one snag there but I'll post that in a different thread