Deitel & Associates, Inc. Logo

Back to

In our XML Basics Tutorial, we introduced XML syntax. We also presented an overview of technologies used to parse, validate and format XML documents. In this tutorial, we provide XML markup for an article and for a business letter. We also demonstrate tools for validating XML markup. This tutorial is intended for people who have read our XML Basics Tutorial or who are familiar with basic XML syntax.

Download the examples for this tutorial here.

[Notes: This tutorial is an excerpt (Section 19.3) of Chapter 19, XML, from our textbook Visual C# 2005 How to Program, 2/e (pages 934-940). This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., Visual C# How to Program, 2/E ©2006. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]

19.3   Structuring Data (Continued)
XML Markup for a Business Letter
Now that we have seen a simple XML document, let's examine a more complex XML document that marks up a business letter (Fig. 19.4). Again, we begin the document with the XML declaration (line 1) that states the XML version to which the document conforms.
Line 5 specifies that this XML document references a DTD. Recall from Section 19.2 that DTDs define the structure of the data for an XML document. For example, a DTD specifies the elements and parent-child relationships between elements permitted in an XML document.
Fig. 19.4 Business letter marked up as XML. 
1   <?xml version = "1.0"?>
2   <!-- Fig. 19.4: letter.xml -->
3   <!-- Business letter marked up as XML -->
5   <!DOCTYPE letter SYSTEM "letter.dtd">
7   <letter>
8      <contact type = "sender">
9         <name>Jane Doe</name>
10        <address1>Box 12345</address1>
11        <address2>15 Any Ave.</address2>
12        <city>Othertown</city>
13        <state>Otherstate</state>
14        <zip>67890</zip>
15        <phone>555-4321</phone>
16        <flag gender = "F" />
17     </contact>
19     <contact type = "receiver">
20        <name>John Doe</name>
21        <address1>123 Main St.</address1>
22        <address2></address2>
23        <city>Anytown</city>
24        <state>Anystate</state>
25        <zip>12345</zip>
26        <phone>555-1234</phone>
27        <flag gender = "M" />
28     </contact>
30     <salutation>Dear Sir:</salutation>
32     <paragraph>It is our privilege to inform you about our new database
33        managed with XML. This new system allows you to reduce the
34        load on your inventory list server by having the client machine
35        perform the work of sorting and filtering the data.
36     </paragraph>
38     <paragraph>Please visit our Web site for availability
39        and pricing.
40     </paragraph>
42     <closing>Sincerely,</closing>
43     <signature>Ms. Jane Doe</signature>
44  </letter>

Error-Prevention Tip 19.1
An XML document is not required to reference a DTD, but validating XML parsers can use a DTD to ensure that the document has the proper structure.
Portability Tip 19.2
Validating an XML document helps guarantee that independent developers will exchange data in a standardized form that conforms to the DTD.
The DTD reference (line 5) contains three items, the name of the root element that the DTD specifies (letter); the keyword SYSTEM (which denotes an external DTD-a DTD declared in a separate file, as opposed to a DTD declared locally in the same file); and the DTD's name and location (i.e., letter.dtd in the current directory). DTD document filenames typically end with the .dtd extension. We discuss DTDs and letter.dtd in detail in Section 19.5.
Several tools (many of which are free) validate documents against DTDs and schemas (discussed in Section 19.5 and Section 19.6, respectively). Microsoft's XML Validator is available free of charge from the Download Sample link at

Page 1 | 2 | 3 | 4
Other XML Tutorials:
XML Basics

Return to Tutorial Index