Zoo tutorials: [ SQL | Linux | XML ]

A Gentle Introduction to xml

Specifying child nodes

We use an external DTD. We specify the children of a node using a form of BNF.

Rules to be enforced

The following symbols may be used:
,A comma is used to separate consecutive elements
?A question mark may come after a term, it is used to allow zero or one occurances
*A star after a term means zero or more of an element
+A plus after a term means one or more of an element

The dtd given is fine for the United Kingdom but it does not suit France or Norway as it should.

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 country SYSTEM "country.dtd">
<country>
  <name>United Kingdom</name>
  <capital>London</capital>
  <queen>Elizabeth II</queen>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Ruritania</name>
  <capital>Strelsau</capital>
  <king>Rudolf</king>
  <king>Michael</king>
  <king>Rudolf</king>
  <!--Should not allow three kings -->
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>France</name>
  <capital>Paris</capital>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Ruritania</name>
  <king>Rudolf</king>
  <!-- capital is missing-->
</country>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Norway</name>
  <capital>Oslo</capital>
  <king>Harald</king>
  <queen>Sonja</queen>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <capital>Strelsau</capital>
  <!-- name is missing -->
</country>