Sonettene som XML
[
Dokument definisjon
][
Stilsett
]
Dokument definisjon
Dokumentdefinisjonen er slik, sonnetes.dtd:
<?xml version="1.0" encoding="ISO-8859-1"?> <!ELEMENT id (#PCDATA)> <!ELEMENT line (#PCDATA)> <!ELEMENT sonnet (id, line+)> <!ELEMENT sonnetes (sonnet+)>
Starten på XML-fila blir slik:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sonnetes SYSTEM "sonnetes.dtd">
<sonnetes>
<sonnet>
<id>I</id>
<line>From fairest creatures we desire increase,</line>
<line>That thereby beauty's rose might never die,</line>
<line>But as the riper should by time decease,</line>
<line>His tender heir might bear his memory:</line>
<line>But thou, contracted to thine own bright eyes,</line>
<line>Feed'st thy light's flame with self-substantial fuel,</line>
<line>Making a famine where abundance lies,</line>
<line>Thyself thy foe, to thy sweet self too cruel.</line>
<line>Thou that art now the world's fresh ornament</line>
<line>And only herald to the gaudy spring,</line>
<line>Within thine own bud buriest thy content</line>
<line>And, tender churl, mak'st waste in niggarding.</line>
<line>Pity the world, or else this glutton be,</line>
<line>To eat the world's due, by the grave and thee.</line>
</sonnet>
<sonnet>
<id>II</id>
<line>When forty winters shall besiege thy brow,</line>
...
.
Stilsett
Vi kopler til et stilsett, sonnetes-xml.css, som ser slik ut:
sonnetes{
color: black;
font-family: "Geneva", "Verdana", "Arial", sans-serif;
font-size: 13px;
text-align: left;
margin-left:10px;
margin-top:10px;
}
sonnete{
margin-top:20px;
display:block;
}
id{
font-size:16;
margin-left:140px;
margin-top:30px;
display:block;
}
line{
color:#783E1E;
margin-left:20px;
display:block;
}
Tilkoplingen skjer i prologen til XML-fila, som nå blir slik:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE sonnetes SYSTEM "sonnetes.dtd"> <?xml-stylesheet type="text/css" href="sonnetes-xml.css"?> <sonnetes> ...
Vi ser at det er mye som kan gjøres for å forbedre dette, men vi konsentrerer oss i de neste modulene på en transformasjon til HTML.