Zoo tutorials: [ SQL | Linux | XML ]

A Gentle Introduction to xml

Repeats and brackets
With answers

We can use * to permit items to be repeated.

The expression (A|B)* allows any number of A nodes or B nodes mixed up together.

The expression (A*|B*) permits any number of A nodes or any number of B nodes - they may not be mixed.

Rule to be enforced:

The dtd given is not correct.


ValidInvalid
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <!-- United kingdom -->
  <county>Kent</county>
  <county>Essex</county>
  <borough>Coventry</borough>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <state>Airstrip 1</state>
  <county>Ambridge</county>
  <!-- May not mix state and county -->
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <!-- USA -->
  <state>Ohio</state>
  <state>Oklahoma</state>
</country>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE country SYSTEM "country.dtd">
<country>
  <state>England</state>
  <borough>Coventry</borough>
  <!-- May not mix state and borough-->
</country>