Download presentation
Presentation is loading. Please wait.
Published byRodney Taylor Modified over 9 years ago
1
2008 Pearson Education, Inc. All rights reserved. 1 14 XML and RSS
2
2008 Pearson Education, Inc. All rights reserved. 2 Knowing trees, I understand the meaning of patience. Knowing grass, I can appreciate persistence. — Hal Borland Like everything metaphysical, the harmony between thought and reality is to be found in the grammar of the language. — Ludwig Wittgenstein
3
2008 Pearson Education, Inc. All rights reserved. 3 I played with an idea, and grew willful; tossed it into the air; transformed it; let it escape and recaptured it; made it iridescent with fancy, and winged it with paradox. — Oscar Wilde
4
2008 Pearson Education, Inc. All rights reserved. 4 OBJECTIVES In this chapter you will learn: To mark up data using XML. How XML namespaces help provide unique XML element and attribute names. To create DTDs and schemas for specifying and validating the structure of an XML document. To create and use simple XSL style sheets to render XML document data. To retrieve and manipulate XML data programmatically using JavaScript. RSS and how to programmatically apply an XSL transformation to an RSS document using JavaScript.
5
2008 Pearson Education, Inc. All rights reserved. 5 14.1 Introduction 14.2 XML Basics 14.3 Structuring Data 14.4 XML Namespaces 14.5 Document Type Definitions (DTDs) 14.6 W3C XML Schema Documents 14.7 XML Vocabularies 14.7.1 MathML TM 14.7.2 Other Markup Languages 14.8 Extensible Stylesheet Language and XSL Transformations 14.9 Document Object Model (DOM) 14.10 RSS 14.11 Wrap-Up 14.12 Web Resources
6
2008 Pearson Education, Inc. All rights reserved. 6 Outline player.xml
7
2008 Pearson Education, Inc. All rights reserved. 7 Software Engineering Observation 14.1 DTDs and schemas are essential for business-to-business (B2B) transactions and mission-critical systems. Validating XML documents ensures that disparate systems can manipulate data structured in standardized ways and prevents errors caused by missing or malformed data.
8
2008 Pearson Education, Inc. All rights reserved. 8 Outline article.xml
9
2008 Pearson Education, Inc. All rights reserved. 9 Portability Tip 14.1 Documents should include the XML declaration to identify the version of XML used. A document that lacks an XML declaration might be assumed to conform to the latest version of XML—when it does not, errors could result.
10
2008 Pearson Education, Inc. All rights reserved. 10 Common Programming Error 14.1 Placing any characters, including white space, before the XML declaration is an error.
11
2008 Pearson Education, Inc. All rights reserved. 11 Common Programming Error 14.2 In an XML document, each start tag must have a matching end tag; omitting either tag is an error. Soon, you will learn how such errors are detected.
12
2008 Pearson Education, Inc. All rights reserved. 12 Common Programming Error 14.3 XML is case sensitive. Using different cases for the start tag and end tag names for the same element is a syntax error.
13
2008 Pearson Education, Inc. All rights reserved. 13 Common Programming Error 14.4 Using a white-space character in an XML element name is an error.
14
2008 Pearson Education, Inc. All rights reserved. 14 Good Programming Practice 14.1 XML element names should be meaningful to humans and should not use abbreviations.
15
2008 Pearson Education, Inc. All rights reserved. 15 Common Programming Error 14.5 Nesting XML tags improperly is a syntax error. For example, hello is an error, because the tag must precede the tag.
16
2008 Pearson Education, Inc. All rights reserved. 16 Fig. 14.3 | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 1 of 3.)
17
2008 Pearson Education, Inc. All rights reserved. 17 Fig. 14.3 | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 2 of 3.)
18
2008 Pearson Education, Inc. All rights reserved. 18 Fig. 14.3 | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 3 of 3.)
19
2008 Pearson Education, Inc. All rights reserved. 19 Outline letter.xml (1 of 2)
20
2008 Pearson Education, Inc. All rights reserved. 20 Outline letter.xml (2 of 2)
21
2008 Pearson Education, Inc. All rights reserved. 21 Error-Prevention Tip 14.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.
22
2008 Pearson Education, Inc. All rights reserved. 22 Portability Tip 14.2 Validating an XML document helps guarantee that independent developers will exchange data in a standardized form that conforms to the DTD.
23
2008 Pearson Education, Inc. All rights reserved. 23 Fig. 14.5 | Validating an XML document with Microsoft’s XML Validator.
24
2008 Pearson Education, Inc. All rights reserved. 24 Fig. 14.6 | Validation result using Microsoft’s XML Validator.
25
2008 Pearson Education, Inc. All rights reserved. 25 Common Programming Error 14.6 Failure to enclose attribute values in double ( "" ) or single ( '' ) quotes is a syntax error.
26
2008 Pearson Education, Inc. All rights reserved. 26 Common Programming Error 14.7 Attempting to create a namespace prefix named xml in any mixture of uppercase and lowercase letters is a syntax error—the xml namespace prefix is reserved for internal use by XML itself.
27
2008 Pearson Education, Inc. All rights reserved. 27 Outline namespace.xml
28
2008 Pearson Education, Inc. All rights reserved. 28 Outline defaultnamespace.xml
29
2008 Pearson Education, Inc. All rights reserved. 29 Software Engineering Observation 14.2 XML documents can have many different structures, and for this reason an application cannot be certain whether a particular document it receives is complete, ordered properly, and not missing data. DTDs and schemas (Section 14.6) solve this problem by providing an extensible way to describe XML document structure. Applications should use DTDs or schemas to confirm whether XML documents are valid.
30
2008 Pearson Education, Inc. All rights reserved. 30 Software Engineering Observation 14.3 Many organizations and individuals are creating DTDs and schemas for a broad range of applications. These collections—called repositories—are available free for download from the web (e.g., www.xml.org, www.oasis-open.org ).
31
2008 Pearson Education, Inc. All rights reserved. 31 Outline letter.dtd
32
2008 Pearson Education, Inc. All rights reserved. 32 Common Programming Error 14.8 For documents validated with DTDs, any document that uses elements, attributes or nesting relationships not explicitly defined by a DTD is an invalid document.
33
2008 Pearson Education, Inc. All rights reserved. 33 Software Engineering Observation 14.4 DTD syntax cannot describe an element’s or attribute’s data type. For example, a DTD cannot specify that a particular element or attribute can contain only integer data.
34
2008 Pearson Education, Inc. All rights reserved. 34 Common Programming Error 14.9 Using markup characters (e.g., and & ) in parsed character data is an error. Use character entity references (e.g., <, > and & ) instead.
35
2008 Pearson Education, Inc. All rights reserved. 35 Fig. 14.10 | XML Validator displaying an error message.
36
2008 Pearson Education, Inc. All rights reserved. 36 Outline book.xml
37
2008 Pearson Education, Inc. All rights reserved. 37 Outline book.xsd
38
2008 Pearson Education, Inc. All rights reserved. 38 Portability Tip 14.3 W3C XML Schema authors specify URI http://www.w3.org/2001/XMLSchema when referring to the XML Schema namespace. This namespace contains predefined elements that comprise the XML Schema vocabulary. Specifying this URI ensures that validation tools correctly identify XML Schema elements and do not confuse them with those defined by document authors.
39
2008 Pearson Education, Inc. All rights reserved. 39 Fig. 14.13 | Some XML Schema types. (Part 1 of 3.)
40
2008 Pearson Education, Inc. All rights reserved. 40 Fig. 14.13 | Some XML Schema types. (Part 2 of 3.)
41
2008 Pearson Education, Inc. All rights reserved. 41 Fig. 14.13 | Some XML Schema types. (Part 3 of 3.)
42
2008 Pearson Education, Inc. All rights reserved. 42 Outline computer.xsd (1 of 2)
43
2008 Pearson Education, Inc. All rights reserved. 43 Outline computer.xsd (2 of 2)
44
2008 Pearson Education, Inc. All rights reserved. 44 Outline laptop.xml
45
2008 Pearson Education, Inc. All rights reserved. 45 Outline mathml1.mml
46
2008 Pearson Education, Inc. All rights reserved. 46 Outline mathml2.html
47
2008 Pearson Education, Inc. All rights reserved. 47 Outline mathml3.html (1 of 2)
48
2008 Pearson Education, Inc. All rights reserved. 48 Outline mathml3.html (2 of 2)
49
2008 Pearson Education, Inc. All rights reserved. 49 Fig. 14.19 | Various markup languages derived from XML. (Part 1 of 2.)
50
2008 Pearson Education, Inc. All rights reserved. 50 Fig. 14.19 | Various markup languages derived from XML. (Part 2 of 2.)
51
2008 Pearson Education, Inc. All rights reserved. 51 Outline sports.xml (1 of 2)
52
2008 Pearson Education, Inc. All rights reserved. 52 Outline sports.xml (2 of 2)
53
2008 Pearson Education, Inc. All rights reserved. 53 Software Engineering Observation 14.5 XSL enables document authors to separate data presentation (specified in XSL documents) from data description (specified in XML documents).
54
2008 Pearson Education, Inc. All rights reserved. 54 Common Programming Error 14.10 You will sometimes see the XML processing instruction written as with a colon rather than a dash. The version with a colon results in an XML parsing error in Firefox.
55
2008 Pearson Education, Inc. All rights reserved. 55 Outline sports.xsl (1 of 2)
56
2008 Pearson Education, Inc. All rights reserved. 56 Outline sports.xsl (2 of 2)
57
2008 Pearson Education, Inc. All rights reserved. 57 Outline sorting.xml
58
2008 Pearson Education, Inc. All rights reserved. 58 Outline sorting.xsl (1 of 4)
59
2008 Pearson Education, Inc. All rights reserved. 59 Outline sorting.xsl (2 of 4)
60
2008 Pearson Education, Inc. All rights reserved. 60 Outline sorting.xsl (3 of 4)
61
2008 Pearson Education, Inc. All rights reserved. 61 Outline sorting.xsl (4 of 4)
62
2008 Pearson Education, Inc. All rights reserved. 62 Fig. 14.24 | XSL style-sheet elements. (Part 1 of 2.)
63
2008 Pearson Education, Inc. All rights reserved. 63 Fig. 14.24 | XSL style-sheet elements. (Part 2 of 2.)
64
2008 Pearson Education, Inc. All rights reserved. 64 Fig. 14.25 | Tree structure for the document article.xml of Fig. 14.2.
65
2008 Pearson Education, Inc. All rights reserved. 65 Outline XMLDOMTraversal.html (1 of 13)
66
2008 Pearson Education, Inc. All rights reserved. 66 Outline XMLDOMTraversal.html (2 of 13)
67
2008 Pearson Education, Inc. All rights reserved. 67 Outline XMLDOMTraversal.html (3 of 13)
68
2008 Pearson Education, Inc. All rights reserved. 68 Outline XMLDOMTraversal.html (4 of 13)
69
2008 Pearson Education, Inc. All rights reserved. 69 Outline XMLDOMTraversal.html (5 of 13)
70
2008 Pearson Education, Inc. All rights reserved. 70 Outline XMLDOMTraversal.html (6 of 13)
71
2008 Pearson Education, Inc. All rights reserved. 71 Outline XMLDOMTraversal.html (7 of 13)
72
2008 Pearson Education, Inc. All rights reserved. 72 Outline XMLDOMTraversal.html (8 of 13)
73
2008 Pearson Education, Inc. All rights reserved. 73 Outline XMLDOMTraversal.html (9 of 13)
74
2008 Pearson Education, Inc. All rights reserved. 74 Outline XMLDOMTraversal.html (10 of 13)
75
2008 Pearson Education, Inc. All rights reserved. 75 Outline XMLDOMTraversal.html (11 of 13)
76
2008 Pearson Education, Inc. All rights reserved. 76 Outline XMLDOMTraversal.html (12 of 13)
77
2008 Pearson Education, Inc. All rights reserved. 77 Outline XMLDOMTraversal.html (13 of 13)
78
2008 Pearson Education, Inc. All rights reserved. 78 Common Programming Error 14.11 Attempting to process the contents of a dynamically loaded XML document in Firefox before the document’s onload event fires is a logic error. The document’s contents are not available until the onload event fires.
79
2008 Pearson Education, Inc. All rights reserved. 79 Portability Tip 14.4 Firefox’s XML parser does not ignore white space used for indentation in XML documents. Instead, it creates text nodes containing the white-space characters.
80
2008 Pearson Education, Inc. All rights reserved. 80 Fig. 14.27 | Common Node properties and methods. (Part 1 of 2.)
81
2008 Pearson Education, Inc. All rights reserved. 81 Fig. 14.27 | Common Node properties and methods. (Part 2 of 2.)
82
2008 Pearson Education, Inc. All rights reserved. 82 Fig. 14.28 | NodeList property and method.
83
2008 Pearson Education, Inc. All rights reserved. 83 Fig. 14.29 | Document properties and methods.
84
2008 Pearson Education, Inc. All rights reserved. 84 Fig. 14.30 | Element property and methods.
85
2008 Pearson Education, Inc. All rights reserved. 85 Fig. 14.31 | Attr properties.
86
2008 Pearson Education, Inc. All rights reserved. 86 Fig. 14.32 | Text methods.
87
2008 Pearson Education, Inc. All rights reserved. 87 Outline xpath.html (1 of 5)
88
2008 Pearson Education, Inc. All rights reserved. 88 Outline xpath.html (2 of 5)
89
2008 Pearson Education, Inc. All rights reserved. 89 Outline xpath.html (3 of 5)
90
2008 Pearson Education, Inc. All rights reserved. 90 Outline xpath.html (4 of 5)
91
2008 Pearson Education, Inc. All rights reserved. 91 Outline xpath.html (5 of 5)
92
2008 Pearson Education, Inc. All rights reserved. 92 Outline sports.xml
93
2008 Pearson Education, Inc. All rights reserved. 93 Fig. 14.35 | XPath expressions and descriptions.
94
2008 Pearson Education, Inc. All rights reserved. 94 Fig. 14.36 | channel elements and descriptions. (Part 1 of 2.)
95
2008 Pearson Education, Inc. All rights reserved. 95 Fig. 14.36 | channel elements and descriptions. (Part 2 of 2.)
96
2008 Pearson Education, Inc. All rights reserved. 96 Fig. 14.37 | item elements and descriptions.
97
2008 Pearson Education, Inc. All rights reserved. 97 Outline RssViewer.html (1 of 5)
98
2008 Pearson Education, Inc. All rights reserved. 98 Outline RssViewer.html (2 of 5)
99
2008 Pearson Education, Inc. All rights reserved. 99 Outline RssViewer.html (3 of 5)
100
2008 Pearson Education, Inc. All rights reserved. 100 Outline RssViewer.html (4 of 5)
101
2008 Pearson Education, Inc. All rights reserved. 101 Outline RssViewer.html (5 of 5)
102
2008 Pearson Education, Inc. All rights reserved. 102 Outline deitel-20.xml (1 of 2)
103
2008 Pearson Education, Inc. All rights reserved. 103 Outline deitel-20.xml (2 of 2)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.