XML Step by Step- P4 ppt

15 175 0
XML Step by Step- P4 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

38 XML Step by Step ■ Display the AUTHOR element in bold (font-weight:bold). ■ Do not display the PAGES element (display:none). Inventory02.css /* File Name: Inventory02.css */ BOOK {display:block; margin-top:12pt; font-size:10pt} TITLE {display:block; font-size:12pt; font-weight:bold; font-style:italic} AUTHOR {display:block; margin-left:15pt; font-weight:bold} BINDING {display:block; margin-left:15pt} PAGES {display:none} PRICE {display:block; margin-left:15pt} Listing 2-4. 9 In your text editor, open the Inventory.xml document. Add the following processing instruction to the end of the document prolog, directly above the INVENTORY element: Chapter 2 Creating and Displaying Your First XML Document 39 2 Your First XML Document <?xml-stylesheet type=”text/css” href=”Inventory02.css”?> This processing instruction links the new CSS you just created to the XML document. 10 To reflect the new filename you’re going to assign, change the comment near the beginning of the document from <! File Name: Inventory.xml > to <! File Name: Inventory02.xml > Listing 2-5 shows the complete XML document. (You’ll find a copy of this listing on the companion CD under the filename Inventory02.xml.) 11 Use your text editor’s Save As command to save a copy of the modified document under the filename Inventory02.xml. Be sure to save it in the same file folder in which you saved Inventory02.css. Inventory02.xml <?xml version=”1.0"?> <! File Name: Inventory02.xml > <?xml-stylesheet type=”text/css” href=”Inventory02.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> 40 XML Step by Step <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> Listing 2-5. Chapter 2 Creating and Displaying Your First XML Document 41 2 Your First XML Document 12 In Windows Explorer or in a folder window, double-click the Inventory02.xml filename to open it. Internet Explorer will open the Inventory02.xml document and display it according to the rules in the linked Inventory02.css style sheet, as shown here (only the first six books are shown; scrolling down would reveal the last two books): tip Part 3 of the book provides complete instructions for displaying XML documents on the Web. I’ll cover cascading style sheets, such as the one you created here, in Chapters 8 and 9. I’ll cover XSLT style sheets in Chapter 12. You’ll learn alternative methods for displaying XML documents on the Web in Chapters 10 and 11. [...]... Well-Formed Documents Chapter 3 Creating Well-Formed XML Documents 50 XML Step by Step 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 xml and version at the beginning of the XML declaration in the example document The processor... Hence, the following is a well-formed XML document: < ?xml version=”1.0"?> XML document > A Minimalist XML Document The prolog in the 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... Listing 3-1 The first line of the example document consists of the XML declaration Although technically the XML declaration is optional, the XML specification recommends including it In addition to making the document self-identifying as XML and specifying the XML version number (which will become important if later versions are developed), it provides a place for... an XML declaration, it must appear at the very beginning of the document (You’re not permitted to include even white space characters before the XML declaration.) The version number in the XML declaration 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. ..48 XML Step by Step hardcover 462 $7.75 The Legend of Sleepy Hollow Washington Irving mass market paperback... of the same type When you add an element to your XML document, you can select any type name you want, provided that you follow these guidelines: I The name must begin with a letter or underscore (_), followed by zero or more letters, digits, periods (.), hyphens (-), or underscores I The XML specification states that names beginning with the letters xml (in any combination of uppercase or lowercase... 4 Finally, the example 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 must either contain a document type declaration or be processed using a separate XML schema file A document type declaration is an additional component,... $7.75 51 Well-Formed Documents Chapter 3 Creating Well-Formed XML Documents Chapter 3 Creating Well-Formed XML Documents 53 The Anatomy of an Element As you’ve seen, an element usually consists of a start-tag, content, and an end-tag Type Start-tag Content End-tag (character data) Unlike HTML, XML requires you to always include both the start-tag and the end-tag The only exception... document in Listing 3-1, which you can place anywhere in the prolog (outside other markup) following the XML declaration A document type declaration contains a document type definition (DTD) that defines the content and structure of a valid XML document Adding Elements to the Document The elements in an XML document contain the actual document information (in Listing 3-1, for example, the titles, authors,... letters) are “reserved for standardization.” Although Internet Explorer doesn’t enforce this restriction, it’s better not to begin names with xml to avoid future problems I You can assign the element name to a namespace by placing a namespace prefix followed by a colon (:) in front of the element name, as explained in “Using Namespaces” on page 69 The element name itself must still conform to the first . and structure, either in a document type definition (DTD) or in an XML schema file. Well-Formed Documents CHAPTER 3 46 XML Step by Step note Permitting XML documents to be merely well-formed, rather than requiring them. carriage-return, or line feed characters. 50 XML Step by Step 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,. listing on the companion CD under the filename Parts .xml. ) Parts .xml < ?xml version=’1.0'?> <! File Name: Parts .xml > < ?xml- stylesheet type=”text/css” href=”Inventory01.css”?> <INVENTORY>

Ngày đăng: 03/07/2014, 07:20

Từ khóa liên quan

Mục lục

  • 00000___07be008c8276e95dbbf4cdee2cdf4385

  • 00002___79c277462295ccdeedc24e5b50330987

  • 00003___7e0229f16eefad21c64fe455ba7840d5

  • 00004___a933fe67c82b988d8a19eb1cf4460489

  • 00005___c78cce8114aad80865103a642f927492

  • 00006___05fca2542d7816c3088c08cb5a953c52

  • 00007___dbcd3471236536641cfe07a8b300c340

  • 00008___51a230a8ae343e365423c24fc4c892b8

  • 00011___81cd371e1c1bacf76929df14a6b72ecd

  • 00012___fa71951b85f2335bba3707db9c9945c3

  • 00013___26bf5c8899f363dbe89421db9772700b

  • 00015___5022a336bf7648f50eb2940bafca422e

  • 00016___8ffef2ab3f4bb8896512f1f52c960d61

  • 00018___b1f3d94f696c5e655031dbac60c8b37d

  • 00020___4c4b41b89831554d0ed8dd83097ce467

  • 00021___0c64d3975047800446fafdd265235893

  • 00022___1f3d089ae9c652aad2afe9c4f573bd2d

  • 00023___4740dcd998da64186e5528f819ce220e

  • 00025___b7b672ade2024f358bfd2d179c77558a

  • 00026___92dda05b322aef279ea8e2bb3247ae41

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan