180 likes | 279 Views
Chapter 5 – Creating Markup with XML.
E N D
Chapter 5 – Creating Markup with XML Outline5.1 Introduction5.2 Introduction to XML Markup5.3 Parsers and Well-formed XML Documents5.4 Parsing an XML Document with msxml5.5 Characters 5.5.1 Character Set 5.5.2 Characters vs. Markup 5.5.3 While Space, Entity References and Built-in Entities 5.5.4 Using Unicode in an XML Document5.6 Markup5.7 CDATA Sections5.8 XML Namespaces5.9 Case Study: A Day Planner Application5.10 Internet and World Wide Web Resources
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.1 : intro.xml --> 4 <!-- Simple introduction to XML markup --> 5 6 <myMessage> 7 <message>Welcome to XML!</message> 8 </myMessage> Fig. 5.1 Simple XML document containing a message.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.4 : lang.xml --> 4 <!-- Demonstrating Unicode --> 5 6 <!DOCTYPE welcome SYSTEM "lang.dtd"> 7 8 <welcome> 9 <from> 10 11 <!-- Deitel and Associates --> 12 دايتَل 13 أند 14 15 <!-- entity --> 16 &assoc; 17 </from> 18 19 <subject> 20 21 <!-- Welcome to the world of Unicode --> 22 أهلاً 23 بكم 24 فيِ 25 عالم 26 27 <!-- entity --> 28 &text; 29 </subject> 30 </welcome> Fig. 5.4 XML document that contains Arabic words
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.5 : usage.xml --> 4 <!-- Usage of elements and attributes --> 5 6 <?xml:stylesheet type = "text/xsl"href = "usage.xsl"?> 7 8 <book isbn = "999-99999-9-X"> 9 <title>Deitel&s XML Primer</title> 10 11 <author> 12 <firstName>Paul</firstName> 13 <lastName>Deitel</lastName> 14 </author> 15 16 <chapters> 17 <preface num = "1" pages = "2">Welcome</preface> 18 <chapter num = "1" pages = "4">Easy XML</chapter> 19 <chapter num = "2" pages = "2">XML Elements?</chapter> 20 <appendix num = "1" pages = "9">Entities</appendix> 21 </chapters> 22 23 <media type = "CD"/> 24 </book> Fig. 5.5 XML document that marks up information about a fictitious book.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.6: letter.xml --> 4 <!-- Business letter formatted with XML --> 5 6 <letter> 7 8 <contact type = "from"> 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> 18 19 <contact type = "to"> 20 <name>Jane 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> 29 Fig. 5.6 XML document that marks up a letter.
30 <salutation>Dear Sir:</salutation> 31 32 <paragraph>It is our privilege to inform you about our new 33 database managed with <bold>XML</bold>. This new system 34 allows you to reduce the load on your inventory list 35 server by having the client machine perform the work of 36 sorting and filtering the data.</paragraph> 37 38 <paragraph>The data in an XML element is normalized, so 39 plain-text diagrams such as 40 /---\ 41 | | 42 \---/ 43 will become gibberish.</paragraph> 44 45 <closing>Sincerely</closing> 46 <signature>Ms. Doe</signature> 47 48 </letter> Fig. 5.6 XML document that marks up a letter. (Part 2)
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.7 : cdata.xml --> 4 <!-- CDATA section containing C++ code --> 5 6 <book title = "C++ How to Program" edition = "3"> 7 8 <sample> 9 // C++ comment 10 if ( this->getX() < 5 && value[ 0 ] != 3 ) 11 cerr << this->displayError(); 12 </sample> 13 14 <sample> 15 <![CDATA[ 16 17 // C++ comment 18 if ( this->getX() < 5 && value[ 0 ] != 3 ) 19 cerr << this->displayError(); 20 ]]> 21 </sample> 22 23 C++ How to Program by Deitel & Deitel 24 </book> Fig. 5.7 Using a CDATA section.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.8 : namespace.xml --> 4 <!-- Namespaces --> 5 6 <directory xmlns:text = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo"> 8 9 <text:file filename = "book.xml"> 10 <text:description>A book list</text:description> 11 </text:file> 12 13 <image:file filename = "funny.jpg"> 14 <image:description>A funny picture</image:description> 15 <image:size width = "200" height = "100"/> 16 </image:file> 17 18 </directory> Fig. 5.8 Listing for namespace.xml.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.9 : defaultnamespace.xml --> 4 <!-- Using Default Namespaces --> 5 6 <directory xmlns = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo"> 8 9 <file filename = "book.xml"> 10 <description>A book list</description> 11 </file> 12 13 <image:file filename = "funny.jpg"> 14 <image:description>A funny picture</image:description> 15 <image:size width = "200"height = "100"/> 16 </image:file> 17 18 </directory> Fig. 5.9 Using default namespaces.
1 <?xml version = "1.0"?> 2 3 <!-- Fig. 5.10 : planner.xml --> 4 <!-- Day Planner XML document --> 5 6 <planner> 7 8 <year value = "2000"> 9 10 <date month = "7" day = "15"> 11 <note time = "1430">Doctor's appointment</note> 12 <note time = "1620">Physics class at BH291C</note> 13 </date> 14 15 <date month = "7" day = "4"> 16 <note>Independence Day</note> 17 </date> 18 Fig. 5.10 Day planner XML document planner.xml.
19 <date month = "7" day = "20"> 20 <note time = "0900">General Meeting in room 32-A</note> 21 </date> 22 23 <date month = "7"day = "20"> 24 <note time = "1900">Party at Joe's</note> 25 </date> 26 27 <date month = "7" day = "20"> 28 <note time = "1300">Financial Meeting in room 14-C</note> 29 </date> 30 31 </year> 32 33 </planner> Fig. 5.10 Day planner XML document planner.xml. (Part 2)