[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: DTD/Schemas with repeated structure

  • From: Wayne Steele <xmlmaster@h...>
  • To: justin@s..., xml-dev@l...
  • Date: Fri, 25 Aug 2000 13:02:34 -0700 (PDT)

dtd example

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@s...>
>
>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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.