Zoo tutorials: [ SQL | Linux | XML ]

A Gentle Introduction to xml

Allowing options

The bar (|) may be used to allow options. A|B means either A or B is permitted. We can use brackets in these regular expressions.

We wish to enforce the following rules:

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>
  <monarch>Elizabeth II</monarch>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Ruritania</name>
  <monarch>Rudolf</monarch>
  <monarch>Michael</monarch>
  <monarch>Rudolf</monarch>
  <!--Should not allow three monarchs -->
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>France</name>
  <president>Sarkozy</president>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Ruritania</name>
  <president>Robert</president>
  <monarch>Rudolf</monarch>
  <!-- Cannot have president and monarch-->
</country>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Norway</name>
  <monarch>Harald</monarch>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <name>Ruritania</name>
  <!-- Should have president or monarch-->
</country>