000522-1

Write an XML DTD for storing an ancestor structure for a person. By an ancestor structure is meant the name and birthdate of the person, and the same information recursively for his or her father and mother, grandfathers and grandmoters, etc., to an unlimited depth. The structure should allow stops at different depth in different branches, when som ancestor is not known any further.

Answer, variant 1

ancestors.dtd:

<!ELEMENT ancestors (father?,mother?)>
<!ATTLIST ancestors
name CDATA #REQUIRED
birthdate CDATA #REQUIRED
>
<!ELEMENT father (ancestors)>
<!ELEMENT mother (ancestors)>

ancestors.xml (example, not required):

<?xml version="1.0" standalone="no"?>
<!DOCTYPE ancestors SYSTEM "http://dsv.su.se/jpalme/internet-course/xml/ancestors.dtd">
<ancestors name="Per Nilsson" birthdate="410201">
<father>
<ancestors name="Erik Nilsson" birthdate="123455">
</ancestors>
</father>
<mother>
<ancestors name="Svea Nilsson" birthdate="120413">
<father>
<ancestors name="Inga Petri" birthdate="1234">
</ancestors>
</father>
<mother>
<ancestors name="Maria Björk" birthdate="18430212">
</ancestors>
</mother>
</ancestors>
</mother>
</ancestors>
13" id="p3"/>
<person name="Peter Svensson" birthdate="19123455" id="p2" mother="p4"/>
<person name="Magda Svensson" birthdate="18871215" id="p4"/>
</ancestor-id>

Note: An advantage with variant 2 over variant 1, might be that it can better cater for cases where the same person is an ancestor in several places.

Answer, Variant 2:

ancestor-id.dtd:

<!ELEMENT ancestor-id (person*)>
<!ELEMENT person EMPTY>
<!ATTLIST person
name CDATA #REQUIRED
birthdate CDATA #REQUIRED
id ID #REQUIRED
mother IDREF #IMPLIED
father IDREF #IMPLIED
>

ancestor-id.xml (example, not required):

<?xml version="1.0" standalone="no"?>
<!DOCTYPE ancestor-id SYSTEM "http://dsv.su.se/jpalme/internet-course/xml/ancestor-id.dtd">
<ancestor-id>
<person name="Per Svensson" birthdate="19410201" id="p1" father="p2" mother="p3"/>

List of exam questions