Creating DTD (Document Type Definition) file using atrributes, fixed, required, implied etc

StackOverflow https://stackoverflow.com/questions/20112658

  •  03-08-2022
  •  | 
  •  

Question

We only talk about DTD and XML in class for 2 days and i have this assignment not sure if im doing it right or did everything that has been asked. Atleast i try, any help will be appreciated!!

Assignment You have been asked to represent airport data where an airport has required attributes name and location; and an implied attribute famous_assoiciation. The famous_assoication attribute is the name of a famous person after whom the airport has been named. An airport is composed of one or more hangers. Each hanger has a number, location and a set of 0 or more associated airlines. Each hanger also has a fixed attribute, length, of 2 miles. An airline has a name, one of more types of aircraft fleets (where a fleet contains one or more planes). A plane has a manufacturer, model, vin and seat_capacity. A plane also has attribute color with a default value of “silver”

You may assume that all data in this system is of type CDATA

This is what i did...

<?xml version = "1.0" encoding ="utf-8"?>

<!ELEMENT airport (hanger+)>
 <!ELEMENT hanger (number, location, airline*)>
 <!ELEMENT number (#PCDATA)>
 <!ELEMENT location (#PCDATA)>
 <!ELEMENT airline (name, aircraft fleets+)>
 <!ELEMENT name (#PCDATA)>
 <!ELEMENT aircraft fleets (plane+)>
 <!ELEMENT plane (manufacturer, model, vin, seat_capacity)>
 <!ELEMENT manufacturer (#PCDATA)>
 <!ELEMENT model (#PCDATA)>
 <!ELEMENT vin (#PCDATA)>
 <!ELEMENT seat_capacity (#PCDATA)>


 <!ATTLIST airport name CDATA #REQUIRED>
 <!ATTLIST airport location CDATA #REQUIRED>
 <!ATTLIST airport famous_assoiciation CDATA #IMPLIED>
 <!ATTLIST plane color CDATA #FIXED "silver">
 <!ATTLIST hanger length CDATA #FIXED "2 miles">
Était-ce utile?

La solution

Your DTD looks pretty good. I only see a few things.


An element can't have a space in the name, so you'll have to change aircraft fleets. There's no reason you couldn't shorten it to fleet.


For readability, it's good practice to put the attribute declaration (ATTLIST) under the element declaration so it's easy to find. You also only need one ATTLIST per element. You can add linebreaks and tabs/spaces to make it easy to read...

<!ELEMENT airport (hanger+)>
<!ATTLIST airport 
          name                CDATA #REQUIRED
          location            CDATA #REQUIRED
          famous_assoiciation CDATA #IMPLIED   >

The color attribute is supposed to have a default value of "silver", but you have it as a fixed value. Just remove #FIXED...

<!ATTLIST plane color CDATA "silver">
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top