R.S. Freedman (April 2000)
A "Well Formed" Extensible Markup Language document ANote.xml that conforms to the XML syntax rules.
<?xml version="1.0"?> <note> <to>Marie</to> <from>Kelman</from> <heading>Reminder</heading> <body>Don't forget to buy another 300 IBM!</body> </note> |
A "Valid" XML document is a "Well Formed" XML document that conforms to the rules of a Document Type Definition (DTD). The following file MyNote.xml has a reference to a DTD MyNote.dtd and a link to a StyleSheet MyNote.xsl:
<?xml version="1.0" ?> <!-- MyNote.xml: A Database in XML. R.S. Freedman 6 December 1999 --> <!-- Includes Document Type Definition (dtd) and html Style Sheet (xsl) --> <!DOCTYPE Collection SYSTEM "MyNote.dtd"> <?xml-stylesheet type="text/xsl" href="MyNote.xsl"?> <!-- Here is the marked up Data: --> <note> <to>Marie</to> <from>Kelman</from> <heading>Reminder</heading> <body> Don't forget to buy another 300 IBM!</body> </note> |
What the "Valid" XML document looks like in a Web Browser (see xsl file MyNote.xsl...)
|
To |
From |
Heading |
|
Marie |
Kelman |
Reminder |
The following is the DTD file -- MyNote.dtd -- that specifies rules for parsing the data "notes".
The DTD uses XML syntax and Standard Generalized Markup Language (SGML) semantics.
<!-- MyNote.dtd: Rules for the Database (Meta-Data) in XML. --> |
The file containing the Extensible Style Language (XSL) really XML again! File MyNote.xsl specifies rules for "formatting" the data in html for Browser display.
<?xml version="1.0" ?>
<!-- MyNote.xsl: An XML Style Sheet to map MyNote.xml into html -->
<!-- R.S. Freedman 6 December 1999 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/"> <!-- match all of note -->
<html> <!-- insert html tags -->
<body>
<xsl:for-each select="note">
<table border="2" bgcolor="yellow">
<tr> <!-- insert table headings -->
<th>To</th>
<th>From</th>
<th>Heading</th>
</tr>
<tr> <!-- get values from note-->
<td>
<xsl:value-of select= "to"/>
</td>
<td>
<xsl:value-of select="from"/>
</td>
<td>
<xsl:value-of select="heading"/>
</td>
</tr>
</table>
<h2> TheMessage:
<xsl:value-of select="body"/>
</h2>
<hr/>
<hr/>
</xsl:for-each> <!-- close all wffs -->
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
XML treats special characters in a manner similar to HTML to prevent ambiguity.
For example, instead of < you should use > in your document. Here are some other aliases:|
Character |
Alias |
|
> |
> |
|
< |
< |
|
& |
& |
|
" |
" |
|
' |
' |
XML also provides entity references to further disambiguate character data from markup data. For further information, see Selena Sol's Web Developer's tutorial.