Zoo tutorials: [ SQL | Linux | XML ]

A Gentle Introduction to xml

ATTLIST values ID and IDREF
With answers

ATTLIST values ID and IDREF

The ATTLIST can specify that an attribute be any of the follow (there are other possiblities):

ID
Must start with a alphabetic character, may not contain spaces. An ID value should be unique within the document.
IDREF
This must be a value that is used as an ID somewhere in the document
IDREFS
A space separated list of IDREF
CDATA
Any parsed character data is permitted
#REQUIRED, #IMPLIED
An attribute may be required or optional. #IMPLIED allows no value to be specified.

Rules to be enforced

Change the dtd so that the xml on the left passes validation and the xml on the right fails validation.


ValidInvalid
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "uk"
         name = "United Kingdom"
       border = "ie"/>
  <country cc = "ie"
         name = "Ireland"
       border = "uk"/>
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "ca"/>
         name = "Canada"
       border = "br"
  <!-- reference to a country
   that has not been listed -->
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "au"
         name = "Austrailia" />
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <!-- No spaces allowed in ID -->
  <country cc = "kn nv"
         name = "Saint Kitts & Nevis"/>
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "ca"
         name = "Canada"
       border = "us"/>
  <country cc = "us"
         name = "United States"
       border = "ca mx"/>
  <country cc = "mx"
         name = "Mexico"
       border = "us"/>
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "3s"
         name = "5pain"/>
  <!-- Should not allow numbers
   at the start of a cc -->
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "mt"
         name = "More Th&amp;gt;n"/>
</planet>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE planet SYSTEM "planet.dtd">
<planet>
  <country cc = "au"
         name = "Austrailia" />
  <country cc = "au"
         name = "Austria" />
  <!-- Should not permit two au codes -->
<</planet>