xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Bagby <willi...@adone.com>
Subject Setting defaults in DTD
Date Tue, 08 May 2001 17:17:22 GMT
I'm still sort of a novice when it comes to DTD's, so please bear with me...

I have an element called <animal-list> which contains one or more
<animal>'s, each with a unique type attribute.  Additionally, each <animal>
contains the same elements.  Here's an example:

<animal-list>
	<animal type="cat">
		<name>Felix</name>
		<color>black</color>
	</animal>  
	<animal type="dog">
		<name>Fido</name>
		<color>brown</color>
	</animal>  
	<animal type="bird">
		<name>Tweety</name>
		<color>yellow</color>
	</animal>
</animal-list>

which has the corresponding DTD:

<!ELEMENT animal-list (animal+)>
<!ELEMENT animal (name,color)>
<!ATTLIST animal type (cat,dog,bird,moose,cow,horse,rabbit,snake) #REQUIRED>

What I'd like to do is specify a default <name> based on what type of
<animal> it is, for example, the default name for a "cat" is Felix, and so
on.  Unless I am mistaken, there is no way to do this.  So, I restructured
the XML so that each child of <animal-list> is distinct:

<animal-list>
	<cat>
		<name>Felix</name>
		<color>black</color>
	</cat>  
	<dog>
		<name>Fido</name>
		<color>brown</color>
	</dog>  
	<bird>
		<name>Tweety</name>
		<color>yellow</color>
	</bird>
</animal-list>

This has it's own drawbacks, not the least of which is a rather unruly DTD,
and it still doesn't allow for defaults.  So I try again:

<animal-list>
	<cat name="Felix" color="black"/>
	<dog name="Fido" color="brown"/>  
	<bird name="Tweety" color="yellow"/>
</animal-list>

OK, now I'm getting somewhere.  Now I can specify defaults.  But my DTD is
still unruly, and it seems a terrible waste to have different elements when
they are really the same element with different characteristics.

Is there a simple and elegant solution to this problem?  I'm of course
making the assumption that one of you has run into this problem before.

Please help me...

William





---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message