OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: DTD/Schemas with repeated structure

[ Lists Home | Date Index | Thread Index ]
  • From: Wayne Steele <xmlmaster@hotmail.com>
  • To: justin@speedlegal.com, xml-dev@lists.xml.org
  • Date: Fri, 25 Aug 2000 13:02:34 -0700 (PDT)


Justin:

First, I don't like the scheme you've used to mark up your data.
There are many alternatives, such as

  <Animal class="Mammal">
      <AnimalName type="latin">Rufus Rufus</AnimalName>
      <AnimalType> something </AnimalType>
  </Animal>

Which is superiour is several respects.
But since this is just illustrative, and you've said "there is no choice", I 
won't belabor the point.

Second, the DTD sample you attached is not well-formed. Here's how Ive 
chosen to interpret it:

<!--=====four lines from DTD=======-->
<!ELEMENT Bird (BirdName,BirdType)>
<!ELEMENT BirdName (#PCDATA)>
<!ELEMENT BirdType (#PCDATA)>
<!ATTLIST Bird BirdName (latin|common) "common">
<!--===============================-->

Which would give an instance document such as:

<!--=================================-->
<!DOCTYPE root SYSTEM "prob.dtd" >
<root>
	<Mammal MammalName="latin">
		<MammalName>Shrewicus Vulgarii</MammalName>
		<MammalType>Shrew, I guess.</MammalType>
	</Mammal>
	<Fish>
		<FishName>Red Bobfish</FishName>
		<FishType>Oily. Scaly. Delicious.</FishType>
	</Fish>
	<Bird BirdName="common">
		<BirdName>The big stupid bird</BirdName>
		<BirdType>ugly</BirdType>
	</Bird>
</root>
<!--==================================-->

Thirdly, You can kinda do this with DTDs as they are.
Replace the four declarations with:

<!--==== Replacement DTD -->
<!ENTITY % c    "Bird" >
<!ENTITY % c.n  "%c;Name" >
<!ENTITY % c.n  "%c;Type" >

<!ELEMENT %c; (%c.n;,%c.t;)>
<!ELEMENT %c.n; (#PCDATA)>
<!ELEMENT %c.t; (#PCDATA)>
<!ATTLIST %c; %c.n; (latin|common) "common">
<!--=====================-->

As you see, making it more modular has made it longer.
This is typical of DTDs.

You would then copy the seven lines above for each additional class (Mammal, 
Fish, etc).

This is still kind of ugly.
I've taken a couple more steps to clean it up a little, and attached the 
complete DTD below.
It validates the above instance document using MSXML3.


-Wayne Steele


<!-- DTD EXAMPLE -->

<!ELEMENT root ANY>

<!ENTITY % c1 	"Mammal" >
<!ENTITY % c2 	"Fish" >
<!ENTITY % c3 	"Bird" >

<!ENTITY % use-c1 "INCLUDE" >
<!ENTITY % use-c2 "INCLUDE" >
<!ENTITY % use-c3 "INCLUDE" >
<!ENTITY % use-c4 "IGNORE" >
<!ENTITY % use-c5 "IGNORE" >

<![ %use-c1; [
<!ENTITY % c1.n "%c1;Name">
<!ENTITY % c1.t "%c1;Type">
<!ELEMENT %c1; (%c1.n;,%c1.t;)>
<!ELEMENT %c1.n; (#PCDATA)>
<!ELEMENT %c1.t; (#PCDATA)>
<!ATTLIST %c1; %c1.n; (latin|common) "common">
]]>

<![ %use-c2; [
<!ENTITY % c2.n "%c2;Name">
<!ENTITY % c2.t "%c2;Type">
<!ELEMENT %c2; (%c2.n;,%c2.t;)>
<!ELEMENT %c2.n; (#PCDATA)>
<!ELEMENT %c2.t; (#PCDATA)>
<!ATTLIST %c2; %c2.n; (latin|common) "common">
]]>

<![ %use-c3; [
<!ENTITY % c3.n "%c3;Name">
<!ENTITY % c3.t "%c3;Type">
<!ELEMENT %c3; (%c3.n;,%c3.t;)>
<!ELEMENT %c3.n; (#PCDATA)>
<!ELEMENT %c3.t; (#PCDATA)>
<!ATTLIST %c3; %c3.n; (latin|common) "common">
]]>

<![ %use-c4; [
<!ENTITY % c4.n "%c4;Name">
<!ENTITY % c4.t "%c4;Type">
<!ELEMENT %c4; (%c4.n;,%c4.t;)>
<!ELEMENT %c4.n; (#PCDATA)>
<!ELEMENT %c4.t; (#PCDATA)>
<!ATTLIST %c4; %c4.n; (latin|common) "common">
]]>

<![ %use-c5; [
<!ENTITY % c5.n "%c5;Name">
<!ENTITY % c5.t "%c5;Type">
<!ELEMENT %c5; (%c5.n;,%c5.t;)>
<!ELEMENT %c5.n; (#PCDATA)>
<!ELEMENT %c5.t; (#PCDATA)>
<!ATTLIST %c5; %c5.n; (latin|common) "common">
]]>

<!-- END DTD Example -->

>From: Justin Lipton <justin@speedlegal.com>
>
>Hi,
>
>I was wondering if anyone has come across this problem.
>We are currently using a DTD that has the following structure.
>Ignore the actual names used here as they are purely for illustrative
>purposes but assume that there is no choice but to use such a structure:
>
><!ELEMENT Mammal (MammalName, MammalType)>
>	<!ELEMENT MammalName (#PCDATA)>
>		<!ATTLIST MammalName (latin|common) "common">
>	<!ELEMENT MammalType (#PCDATA)>
>
><!ELEMENT Fish (FishName, FishType)>
>		<!ATTLIST FishName (latin|common) "common">
>	<!ELEMENT FishType (#PCDATA)>
>
><!ELEMENT Bird (BirdName, BirdType)>
>		<!ATTLIST BirdName (latin|common) "common">
>	<!ELEMENT BirdType (#PCDATA)>
>
>Image dozens of elements like this!
>
>Is there a way (either with a Schema or a DTD) to generalise this type of
>structure such that:
><!ELEMENT * (*Name, *Type)>
>		<!ATTLIST *Name (latin|common) "common">
>	<!ELEMENT *Type (#PCDATA)>
>
>Cheers,
>Justin.
>
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS