Microsoft Xml Step by Step with Cdrom

Microsoft Xml Step by Step with Cdrom

5.0 1
by Microsoft Press, Michael J. Young
     
 

This all-in-one, step-by-step guide to building XML applications presents Web developers, professional programmers, and even non-programmers with examples and tools to put XML to work right away, without requiring extensive technical knowledge. It focuses on teaching the most practical uses for XML, with a heavy emphasis on hands-on learning and project-specific

See more details below

Overview

This all-in-one, step-by-step guide to building XML applications presents Web developers, professional programmers, and even non-programmers with examples and tools to put XML to work right away, without requiring extensive technical knowledge. It focuses on teaching the most practical uses for XML, with a heavy emphasis on hands-on learning and project-specific examples. The CD contains extensive XML sample code and scripts and Internet Explorer 5.

Product Details

ISBN-13:
9780735610200
Publisher:
Microsoft Press
Publication date:
07/07/2000
Series:
DV-DLT Fundamentals Series
Edition description:
BK&CD-ROM
Pages:
375
Product dimensions:
7.39(w) x 9.25(h) x 1.19(d)

Read an Excerpt


Chapter 3: Creating Well-Formed XML Documents

  • The Parts of a Well-Formed XML Document
    • A Minimalist XML Document

  • Adding Elements to the Document
    • The Anatomy of an Element
    • Types of Element Content
    • Empty Elements
    • Create Different Types of Elements

  • Adding Attributes to Elements
    • Rules for Creating Attributes
    • Rules for Legal Attribute Values
    • Convert Content to Attributes

In this chapter, you'll learn the basic techniques for creating a well-formed XML document. A well-formed document is one that meets the minimal set of criteria for a conforming XML document. When you create a well-formed XML document, you can pitch right in and begin adding elements as you need them and entering your document's data, just as you do when you create an HTML Web page. (Although, as you learned in the previous chapters, in an XML document you invent your own elements rather than using predefined ones.) And you'll have no problem handling and displaying any well-formed XML document in Internet Explorer 5.

In Chapter 5, you'll learn how to create a valid XML document: a document that is not only well-formed but also conforms to a more rigid set of constraints. Creating a valid XML document is not as easy as creating one that is only well-formed. Before you begin adding elements and data to a valid document, you must fully define the structure of the document in a document type declaration added to the document's prolog. In Chapter 5 you'll learn that there are some advantages to making documents valid, especially if you or others are creating a group of similar documents.

In this chapter, you'll first learn about all the required and optional parts of a well-formed XML document. Next you'll discover how to add information to an XML document by defining the document's elements. You'll then learn how to supply additional document information by adding attributes to the elements.

The Parts of a Well-Formed XML Document

As you learned in Chapter 2, an XML document consists of two main parts: the prolog and the document element (which is also known as the root element). In addition, following the document element, a well-formed XML document can include comments, processing instructions, and white space. Here's an example of a well-formed XML document that shows the different document parts and the items you can add to each part:

Click to view graphic

Listing 3-1 shows the complete version of this example document. (You'll find a copy of this listing on the companion CD under the filename Parts.xml.)

Parts.xml

<?xml version='1.0' standalone='yes' ?><!-- File Name: Parts.xml --> <?xml-stylesheet type="text/css" href="Inventory01.css"> <INVENTORY> <BOOK> <TITLE>The Adventures of Huckleberry Finn</TITLE> <AUTHOR>Mark Twain</AUTHOR> <BINDING>mass market paperback</BINDING> <PAGES>298</PAGES> <PRICE>$5.49</PRICE> </BOOK> <BOOK> <TITLE>Leaves of Grass</TITLE> <AUTHOR>Walt Whitman</AUTHOR> <BINDING>hardcover</BINDING> <PAGES>462</PAGES> <PRICE>$7.75</PRICE> </BOOK> <BOOK> <TITLE>The Legend of Sleepy Hollow</TITLE> <AUTHOR>Washington Irving</AUTHOR> <BINDING>mass market paperback</BINDING> <PAGES>98</PAGES> <PRICE>$2.95</PRICE> </BOOK> <BOOK> <TITLE>The Marble Faun</TITLE> <AUTHOR>Nathaniel Hawthorne</AUTHOR> <BINDING>trade paperback</BINDING> <PAGES>473</PAGES> <PRICE>$10.95</PRICE> </BOOK> <BOOK> <TITLE>Moby-Dick</TITLE> <AUTHOR>Herman Melville</AUTHOR> <BINDING>hardcover</BINDING> <PAGES>724</PAGES> <PRICE>$9.95</PRICE> </BOOK> <BOOK> <TITLE>The Portrait of a Lady</TITLE> <AUTHOR>Henry James</AUTHOR> <BINDING>mass market paperback</BINDING> <PAGES>256</PAGES> <PRICE>$4.95</PRICE> </BOOK> <BOOK> <TITLE>The Scarlet Letter</TITLE> <AUTHOR>Nathaniel Hawthorne</AUTHOR> <BINDING>trade paperback</BINDING> <PAGES>253</PAGES> <PRICE>$4.25</PRICE> </BOOK> <BOOK> <TITLE>The Turn of the Screw</TITLE> <AUTHOR>Henry James</AUTHOR> <BINDING>trade paperback</BINDING> <PAGES>384</PAGES> <PRICE>$3.35</PRICE> </BOOK></INVENTORY> <!-- Comments, processing instructions, and white space can also appear after the document element. --> <?MyApp Parm1="value 1" Parm2="value 2" ?

Listing 3-1.

The version number in the XML declaration at the start of the document prolog can be delimited with either single or double quotes. In general, quoted strings in XML markup-known as literals-can use either single or double quotes. Thus, both of the following are legal:

<?xml version='1.0'?> <?xml version="1.0"

The XML declaration in the example document in Listing 3-1 also includes a standalone document declaration (standalone='yes'). This declaration can be used in some XML documents to simplify document processing. (I'll discuss the standalone document declaration in Chapter 6.) The example document includes a comment in the prolog and another comment following the document element. (You'll learn more about comments in Chapter 4.)

The document also contains a blank line labeled "white space" in the prolog and another that follows the document element. White space consists of one or more space, tab, carriage return, or linefeed characters. To make an XML document more readable to humans, you can freely add white space between XML markup (such as start-tags, end-tags, comments, and processing instructions) and also in many places within markup. (For instance, the space between the 'yes' and the ? at the end of the XML declaration in the example document.) The processor simply ignores white space unless it's within an element that directly contains character data. (In this case, the processor passes the white space to the application as part of the element's character data.)

The example document has a processing instruction in the prolog and another that follows the document element. (I'll discuss processing instructions in Chapter 4.)

Finally, the document includes the sine qua non of an XML document: the document element. Creating the document element and the nested elements that it contains is the focus of this chapter.


NOTE:
As you'll learn in Chapter 5, a valid XML document needs to contain one additional component that isn't included in the example document in Listing 3-1: a document type declaration, which you can place anywhere in the prolog, outside of other markup, following the XML declaration. A document type declaration defines the structure of a valid XML document.

A Minimalist XML Document

The prolog in the example XML document in Listing 3-1 contains an example of each of the items allowed within a prolog. Note, however, that these items are all optional (although the XML specification states that you "should" include the XML declaration). Hence, the prolog itself is optional, and the following minimalist document, which contains only a simple document element, conforms to the XML standard for a well-formed document...

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >