Zoo tutorials: [ SQL | Linux | XML ]

A Gentle Introduction to xml

Payment problem
With answers

A tricky problem involving alternative payment methods.

Customers at the till may pay with a combination of credit cards and cash.

Make up a DTD so that the XML on the left passes validation but the XML on the right fails validation. The DTD given is too permissive - it allows any combination of card and cash.


ValidInvalid
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <card/>
  <cash/>
</payment>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <cash/>
  <cash/>
  <!-- two cash payments :o( -->
</payment>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <cash/>
</payment>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <!-- no payment at all :o( -->
</payment>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <card/>
  <card/>
</payment>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE payment SYSTEM "payment.dtd">
<payment>
  <cash/>
  <card/>
  <!-- cash before card :o( -->
</payment>