Visual C# 2005
How to Program, 2/e
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)
Viewing an XML Document in Internet Explorer
The XML document in Fig. 19.2 is simply a text file named article.xml. This document does not contain formatting information for the article. This is because XML is a technology for describing the structure of data. Formatting and displaying data from an XML document are application-specific issues. For example, when the user loads article.xml in Internet Explorer (IE), MSXML (Microsoft XML Core Services) parses and displays the document's data. Internet Explorer uses a built-in style sheet to format the data. Note that the resulting format of the data (Fig. 19.3) is similar to the format of the listing in Fig. 19.2. In Section 19.7, we show how to create style sheets to transform your XML data into various formats suitable for display.
Note the minus sign (-) and plus sign (+) in the screen shots of Fig. 19.3. Although these symbols are not part of the XML document, Internet Explorer places them next to every container element. A minus sign indicates that Internet Explorer is displaying the container element's child elements. Clicking the minus sign next to an element collapses that element (i.e., causes Internet Explorer to hide the container element's children and replace the minus sign with a plus sign). Conversely, clicking the plus sign next to an element expands that element (i.e., causes Internet Explorer to display the container element's children and replace the plus sign with a minus sign). This behavior is similar to viewing the directory structure using Windows Explorer. In fact, a directory structure often is modeled as a series of tree structures, in which the root of a tree represents a drive letter (e.g., C:), and nodes in the tree represent directories. Parsers often store XML data as tree structures to facilitate efficient manipulation, as discussed in Section 19.8.
article.xml displayed by Internet Explorer.
[Note: In Windows XP Service Pack 2, by default Internet Explorer displays all the XML elements in expanded view, and clicking the minus sign (Fig. 19.3(a) does not do anything. So by default, Windows will not be able to collapse the element. To enable this functionality, right click the Information Bar just below the Address field and select Allow Blocked Content.... Then click Yes in the popup window that appears.]