 2008 Pearson Education, Inc. All rights reserved. 1 14 XML and RSS.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
An Introduction to XML Based on the W3C XML Recommendations.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
3 November 2008CIS 340 # 1 Topics To define XML as a technology To place XML in the context of system architectures.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
 2006 Pearson Education, Inc. All rights reserved Extensible Markup Language (XML)
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic XML.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
ECA 228 Internet/Intranet Design I Intro to XML. ECA 228 Internet/Intranet Design I HTML markup language very loose standards browsers adjust for non-standard.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
 2008 Pearson Education, Inc. All rights reserved XML.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
XP New Perspectives on XML Tutorial 3 1 DTD Tutorial – Carey ISBN
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
 2008 Pearson Education, Inc. All rights reserved XML and RSS.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 20 – Extensible Markup Language (XML) Outline 20.1 Introduction 20.2 Structuring Data 20.3 XML.
 2003 Prentice Hall, Inc. All rights reserved. 3 rd Edition Slide 1 Chapter 20 – Extensible Markup Language (XML) Outline 20.1 Introduction 20.2 Structuring.
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language)  XML is a markup language for creating documents containing structured information.
Introduction to XML 1. XML XML started out as a standard data exchange format for the Web Yet, it has quickly become the fundamental instrument in the.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
XHTML1 Building Document Structure Chapter 2. XHTML2 Objectives In this chapter, you will: Learn how to create Extensible Hypertext Markup Language (XHTML)
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
Avoid using attributes? Some of the problems using attributes: Attributes cannot contain multiple values (child elements can) Attributes are not easily.
 2008 Pearson Education, Inc. All rights reserved XML and RSS.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XML Extensible Markup Language
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language  XML is a markup language for creating documents containing structured information.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 20 – Extensible Markup Language (XML) Outline 20.1 Introduction 20.2 Structuring Data 20.3 XML.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
1 Credits Prepared by: Rajendra P. Srivastava Ernst & Young Professor University of Kansas Sponsored by: Ernst & Young, LLP (August 2005) XBRL Module Part.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Understanding How XML Works Ellen Pearlman Eileen Mullin Programming the.
Tutorial 13 Validating Documents with Schemas
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
COP 3813 Intro to Internet Computing Prof. Roy Levow XML.
Chapter 15: XML TP2543 Web Programming Mohammad Faidzul Nasrudin.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
XML Introduction to XML Extensible Markup Language.
XML Schema – XSLT Week 8 Web site:
1 XML and RSS. 2 Knowing trees, I understand the meaning of patience. Knowing grass, I can appreciate persistence. — Hal Borland Like everything metaphysical,
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Unit 4 Representing Web Data: XML
14 XML and RSS.
Chapter 7 Representing Web Data: XML
Chapter 20 – Extensible Markup Language (XML)
14 XML.
Presentation transcript:

 2008 Pearson Education, Inc. All rights reserved XML and RSS

 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

 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

 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.

 2008 Pearson Education, Inc. All rights reserved 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 MathML TM Other Markup Languages 14.8 Extensible Stylesheet Language and XSL Transformations 14.9 Document Object Model (DOM) RSS Wrap-Up Web Resources

 2008 Pearson Education, Inc. All rights reserved Introduction XML is a portable, widely supported, open (i.e., nonproprietary) technology for data storage and exchange

 2008 Pearson Education, Inc. All rights reserved XML Basics XML documents are readable by both humans and machines XML permits document authors to create custom markup for any type of information – Can create entirely new markup languages that describe specific types of data, including mathematical formulas, chemical molecular structures, music and recipes An XML parser is responsible for identifying components of XML documents (typically files with the.xml extension) and then storing those components in a data structure for manipulation An XML document can optionally reference a Document Type Definition (DTD) or schema that defines the XML document’s structure An XML document that conforms to a DTD/schema (i.e., has the appropriate structure) is valid If an XML parser (validating or nonvalidating) can process an XML document successfully, that XML document is well-formed

 2008 Pearson Education, Inc. All rights reserved. 8 Outline player.xml Start tags and end tags enclose data or other elements The root element contains all other elements in the document

 2008 Pearson Education, Inc. All rights reserved. 9 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.

 2008 Pearson Education, Inc. All rights reserved Structuring Data An XML document begins with an optional XML declaration, which identifies the document as an XML document. The version attribute specifies the version of XML syntax used in the document. XML comments begin with An XML document contains text that represents its content (i.e., data) and elements that specify its structure. XML documents delimit an element with start and end tags The root element of an XML document encompasses all its other elements XML element names can be of any length and can contain letters, digits, underscores, hyphens and periods – Must begin with either a letter or an underscore, and they should not begin with “ xml ” in any combination of uppercase and lowercase letters, as this is reserved for use in the XML standards

 2008 Pearson Education, Inc. All rights reserved Structuring Data (Cont.) When a user loads an XML document in a browser, a parser parses the document, and the browser uses a style sheet to format the data for display IE and Firefox each display minus ( – ) or plus ( + ) signs next to all container elements. A minus sign indicates that all child elements are being displayed. When clicked, a minus sign becomes a plus sign (which collapses the container element and hides all the children), and vice versa Data can be placed between tags or in attributes (name/value pairs that appear within the angle brackets of start tags). Elements can have any number of attributes

 2008 Pearson Education, Inc. All rights reserved. 12 Outline article.xml The name elements are nested within the author element The author element is a containing element because it has child elements

 2008 Pearson Education, Inc. All rights reserved. 13 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.

 2008 Pearson Education, Inc. All rights reserved. 14 Common Programming Error 14.1 Placing any characters, including white space, before the XML declaration is an error.

 2008 Pearson Education, Inc. All rights reserved. 15 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.

 2008 Pearson Education, Inc. All rights reserved. 16 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.

 2008 Pearson Education, Inc. All rights reserved. 17 Common Programming Error 14.4 Using a white-space character in an XML element name is an error.

 2008 Pearson Education, Inc. All rights reserved. 18 Good Programming Practice 14.1 XML element names should be meaningful to humans and should not use abbreviations.

 2008 Pearson Education, Inc. All rights reserved. 19 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.

 2008 Pearson Education, Inc. All rights reserved. 20 Fig | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 1 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 21 Fig | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 2 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 22 Fig | article.xml displayed by Internet Explorer 7 and Firefox 2. (Part 3 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 23 Outline letter.xml (1 of 2) The DOCTYPE specifies an external DTD in the file letter.dtd Data can be stored as attributes, which appear in an element’s start tag flag is an empty element because it contains no child elements or content

 2008 Pearson Education, Inc. All rights reserved. 24 Outline letter.xml (2 of 2)

 2008 Pearson Education, Inc. All rights reserved. 25 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.

 2008 Pearson Education, Inc. All rights reserved. 26 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.

 2008 Pearson Education, Inc. All rights reserved. 27 Fig | Validating an XML document with Microsoft’s XML Validator.

 2008 Pearson Education, Inc. All rights reserved. 28 Fig | Validation result using Microsoft’s XML Validator.

 2008 Pearson Education, Inc. All rights reserved. 29 Common Programming Error 14.6 Failure to enclose attribute values in double ( "" ) or single ( '' ) quotes is a syntax error.

 2008 Pearson Education, Inc. All rights reserved Namespaces XML namespaces provide a means for document authors to prevent naming collisions Each namespace prefix is bound to a uniform resource identifier (URI) that uniquely identifies the namespace – A URI is a series of characters that differentiate names – Document authors create their own namespace prefixes – Any name can be used as a namespace prefix, but the namespace prefix xml is reserved for use in XML standards To eliminate the need to place a namespace prefix in each element, authors can specify a default namespace for an element and its children – We declare a default namespace using keyword xmlns with a URI (Uniform Resource Identifier) as its value Document authors commonly use URLs (Uniform Resource Locators) for URIs, because domain names (e.g., deitel.com ) in URLs must be unique

 2008 Pearson Education, Inc. All rights reserved. 31 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.

 2008 Pearson Education, Inc. All rights reserved. 32 Outline namespace.xml Two namespaces are specified using URNs The namespace prefixes are used in element names throughout the document

 2008 Pearson Education, Inc. All rights reserved. 33 Outline defaultnamespace.xml The default namespace is set in the directory element Elements with no namespace prefix use the default namespace

 2008 Pearson Education, Inc. All rights reserved Document Type Definitions (DTDs) DTDs and schemas specify documents’ element types and attributes, and their relationships to one another DTDs and schemas enable an XML parser to verify whether an XML document is valid (i.e., its elements contain the proper attributes and appear in the proper sequence) A DTD expresses the set of rules for document structure using an EBNF (Extended Backus-Naur Form) grammar In a DTD, an ELEMENT element type declaration defines the rules for an element. An ATTLIST attribute-list declaration defines attributes for a particular element

 2008 Pearson Education, Inc. All rights reserved. 35 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.

 2008 Pearson Education, Inc. All rights reserved. 36 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., ).

 2008 Pearson Education, Inc. All rights reserved. 37 Outline letter.dtd Define the requirements for the letter element Define the requirements for the contact element A contact element may have a type attribute, but it is not required Each of these elements contains parsed character data The flag element must be empty and its gender attribute must be set to either M or F. If there is no gender attribute, gender defaults to M

 2008 Pearson Education, Inc. All rights reserved. 38 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.

 2008 Pearson Education, Inc. All rights reserved. 39 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.

 2008 Pearson Education, Inc. All rights reserved. 40 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.

 2008 Pearson Education, Inc. All rights reserved. 41 Fig | XML Validator displaying an error message.

 2008 Pearson Education, Inc. All rights reserved W3C XML Schema Documents Unlike DTDs – Schemas use use XML syntax not EBNF grammar – XML Schema documents can specify what type of data (e.g., numeric, text) an element can contain An XML document that conforms to a schema document is schema valid Two categories of types exist in XML Schema: simple types and complex types – Simple types cannot contain attributes or child elements; complex types can Every simple type defines a restriction on an XML Schema-defined schema type or on a user-defined type Complex types can have either simple content or complex content – Both can contain attributes, but only complex content can contain child elements Whereas complex types with simple content must extend or restrict some other existing type, complex types with complex content do not have this limitation

 2008 Pearson Education, Inc. All rights reserved. 43 Outline book.xml

 2008 Pearson Education, Inc. All rights reserved. 44 Outline book.xsd Specify the namespace of the elements that this schema defines Define the books element Define the requirements for any element of type BooksType An element of type BooksType must contian one or more book elements, which have type SingleBookType A SingleBookType element has a title element, which contains a string

 2008 Pearson Education, Inc. All rights reserved. 45 Portability Tip 14.3 W3C XML Schema authors specify URI 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.

 2008 Pearson Education, Inc. All rights reserved. 46 Fig | Some XML Schema types. (Part 1 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 47 Fig | Some XML Schema types. (Part 2 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 48 Fig | Some XML Schema types. (Part 3 of 3.)

 2008 Pearson Education, Inc. All rights reserved. 49 Outline computer.xsd (1 of 2) Define a simpleType that contains a decimal whose value is 2.1 or greater Define a complexType with simpleContent so that it can contain only attributes, not child elements The CPU element’s data must be of type string, and it must have an attribute model containing a string

 2008 Pearson Education, Inc. All rights reserved. 50 Outline computer.xsd (2 of 2) The all element specifies a list of elements that must be included, in any order, in the document The types defined in the last slide are used by these elements

 2008 Pearson Education, Inc. All rights reserved. 51 Outline laptop.xml

 2008 Pearson Education, Inc. All rights reserved XML Vocabularies Some XML vocabularies – MathML (Mathematical Markup Language) – Scalable Vector Graphics (SVG) – Wireless Markup Language (WML) – Extensible Business Reporting Language (XBRL) – Extensible User Interface Language (XUL) – Product Data Markup Language (PDML) – W3C XML Schema – Extensible Stylesheet Language (XSL) MathML markup describes mathematical expressions for display – Divided into two types of markup—content markup and presentation markup – Content MathML allows programmers to write mathematical notation specific to different areas of mathematics – Presentation MathML is directed toward formatting and displaying mathematical notation – By convention, MathML files end with the.mml filename extension

 2008 Pearson Education, Inc. All rights reserved XML Vocabularies (Cont.) MathML document root node is the math element – Default namespace is mn element – marks up a number mo element – marks up an operator Entity reference &InvisibleTimes; – indicates a multiplication operation without explicit symbolic representation msup element – represents a superscript – has two children—the expression to be superscripted (i.e., the base) and the superscript (i.e., the exponent) – Correspondingly, the msub element represents a subscript To display variables, use identifier element mi

 2008 Pearson Education, Inc. All rights reserved XML Vocabularies (Cont.) mfrac element – displays a fraction – If either the numerator or the denominator contains more than one element, it must appear in an mrow element mrow element – groups elements that are positioned horizontally in an expression Entity reference ∫ – represents the integral symbol msubsup element – specifies the subscript and superscript of a symbol – Requires three child elements—an operator, the subscript expression and the superscript expression msqrt element – represents a square-root expression Entity reference δ – represents a lowercase delta symbol

 2008 Pearson Education, Inc. All rights reserved. 55 Outline mathml1.mml The math element contains number and operator elements that represent the equation = 5

 2008 Pearson Education, Inc. All rights reserved. 56 Outline mathml2.html &InvisibleTimes; represents an implied multiplication operator The msup element contains two elements: a base and a superscript The mfrac element contains two elements: a numerator and a denominator

 2008 Pearson Education, Inc. All rights reserved. 57 Outline mathml3.html (1 of 2) ∫ represents the integral symbol mrow groups elements horizontally in an expression msqrt puts its contents underneath a square root symbol

 2008 Pearson Education, Inc. All rights reserved. 58 Outline mathml3.html (2 of 2) δ represents the delta symbol

 2008 Pearson Education, Inc. All rights reserved. 59 Fig | Various markup languages derived from XML. (Part 1 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 60 Fig | Various markup languages derived from XML. (Part 2 of 2.)

 2008 Pearson Education, Inc. All rights reserved Extensible Stylehsheet Language and XSL Transformations Convert XML into any text-based document XSL documents have the extension.xsl XPath – A string-based language of expressions used by XML and many of its related technologies for effectively and efficiently locating structures and data (such as specific elements and attributes) in XML documents – Used to locate parts of the source-tree document that match templates defined in an XSL style sheet. When a match occurs (i.e., a node matches a template), the matching template executes and adds its result to the result tree. When there are no more matches, XSLT has transformed the source tree into the result tree. XSLT does not analyze every node of the source tree – it selectively navigates the source tree using XPath’s select and match attributes For XSLT to function, the source tree must be properly structured – Schemas, DTDs and validating parsers can validate document structure before using XPath and XSLTs XSL style sheets can be connected directly to an XML document by adding an xml:stylesheet processing instruction to the XML document

 2008 Pearson Education, Inc. All rights reserved Extensible Stylehsheet Language and XSL Transformations (Cont.) Two tree structures are involved in transforming an XML document using XSLT – source tree (the document being transformed) – result tree (the result of the transformation) XPath character / (a forward slash) – Selects the document root – In XPath, a leading forward slash specifies that we are using absolute addressing – An XPath expression with no beginning forward slash uses relative addressing XSL element value-of – Retrieves an attribute’s value – symbol specifies an attribute node XSL node-set function name – Retrieves the current node’s element name XSL node-set function text – Retrieves the text between an element’s start and end tags The XPath expression //* – Selects all the nodes in an XML document

 2008 Pearson Education, Inc. All rights reserved. 63 Outline sports.xml (1 of 2) The xml-stylesheet declaration points to an XSL style sheet for this document

 2008 Pearson Education, Inc. All rights reserved. 64 Outline sports.xml (2 of 2)

 2008 Pearson Education, Inc. All rights reserved. 65 Software Engineering Observation 14.5 XSL enables document authors to separate data presentation (specified in XSL documents) from data description (specified in XML documents).

 2008 Pearson Education, Inc. All rights reserved. 66 Common Programming Error 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.

 2008 Pearson Education, Inc. All rights reserved. 67 Outline sports.xsl (1 of 2) Use xsl-output to write a doctype.

 2008 Pearson Education, Inc. All rights reserved. 68 Outline sports.xsl (2 of 2) Write the following HTML for each game element in the sports element that is contained in the root element Write the value of the game ’s id attribute in a table cell Write the value of the game ’s name child element in a table cell Write the value of the game ’s paragraph child element in a table cell

 2008 Pearson Education, Inc. All rights reserved. 69 Outline sorting.xml The chapters are out of order here, but our XSL transformation will sort the data before displaying it

 2008 Pearson Education, Inc. All rights reserved. 70 Outline sorting.xsl (1 of 4) Apply the templates in this document to the document root’s child nodes Set the XHTML document’s title to show the book’s ISBN number and title

 2008 Pearson Education, Inc. All rights reserved. 71 Outline sorting.xsl (2 of 4) Output the enclosed XHTML for each element in the frontmatter element, which is contained in the chapters element Sort the chapter elements by the number contained in their number attribute in ascending order

 2008 Pearson Education, Inc. All rights reserved. 72 Outline sorting.xsl (3 of 4) Sort the appendices alphabetically by their number attributes in ascending order

 2008 Pearson Education, Inc. All rights reserved. 73 Outline sorting.xsl (4 of 4)

 2008 Pearson Education, Inc. All rights reserved. 74 Fig | XSL style-sheet elements. (Part 1 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 75 Fig | XSL style-sheet elements. (Part 2 of 2.)

 2008 Pearson Education, Inc. All rights reserved Document Object Model Retrieving data from an XML document using traditional sequential file processing techniques is neither practical nor efficient Some XML parsers store document data as tree structures in memory – This hierarchical tree structure is called a Document Object Model (DOM) tree, and an XML parser that creates this type of structure is known as a DOM parser – Each element name is represented by a node – A node that contains other nodes is called a parent node – A parent node can have many children, but a child node can have only one parent node – Nodes that are peers are called sibling nodes – A node’s descendant nodes include its children, its children’s children and so on – A node’s ancestor nodes include its parent, its parent’s parent and so on

 2008 Pearson Education, Inc. All rights reserved Document Object Model (Cont.) Many of the XML DOM capabilities are similar or identical to those of the XHTML DOM The DOM tree has a single root node, which contains all the other nodes in the document window.ActiveXObject – If this object exists, the browser is Internet Explorer – Loads Microsoft’s MSXML parser is used to manipulate XML documents in Internet Explorer MSXML load method – loads an XML document childNodes property of a document – contains a list of the XML document’s top-level nodes If the browser is Firefox 2, then the document object’s implementation property and the implementation property’s createDocument method will exist Firefox loads each XML document asynchronously – You must use the XML document’s onload property to specify a function to call when the document finishes loading to ensure that you can access the document’s contents nodeType property of a node – contains the type of the node

 2008 Pearson Education, Inc. All rights reserved Document Object Model (Cont.) Nonbreaking spaces ( ) – spaces that the browser is not allowed to collapse or that can be used to keep words together. nodeName property of a node – Obtain the name of an element childNodes list of a node – Nonzero if the currrent node has children nodeValue property – Returns the value of an element firstChild property of a node – Refers to the first child of a given node lastChild property of a node – refers to the last child of a given node nextSibling property of a node – refers to the next sibling in a list of children of a particular node. previousSibling property of a node – refers to the current node’s previous sibling parentNode property of a node – refers to the current node’s parent node

 2008 Pearson Education, Inc. All rights reserved Document Object Model (Cont.) Use XPath expressions to specify search criteria – In IE7, the XML document object’s selectNodes method receives an XPath expression as an argument and returns a collection of elements that match the expression – Firefox 2 searches for XPath matches using the XML document object’s evaluate method, which receives five arguments the XPath expression the document to apply the expression to a namespace resolver a result type an XPathResult object into which to place the results If the last argument is null, the function simply returns a new XPathResult object containing the matches The namespace resolver argument can be null if you are not using XML namespace prefixes in the XPath processing

 2008 Pearson Education, Inc. All rights reserved. 80 Fig | Tree structure for the document article.xml of Fig

 2008 Pearson Education, Inc. All rights reserved. 81 Outline XMLDOMTraversal.html (1 of 13) Load the document using the IE-specific ActiveXObject

 2008 Pearson Education, Inc. All rights reserved. 82 Outline XMLDOMTraversal.html (2 of 13) Load the document using other browsers In either case, call buildHTML and displayDoc methods once the document has loaded

 2008 Pearson Education, Inc. All rights reserved. 83 Outline XMLDOMTraversal.html (3 of 13) Loop through children and decide what to do depending on nodeType If the node is an element, display its name If the node has children, call buildHTML recursively to handle the children If a text node or comment node is not simply indentation white space, add its value to the outputHTML

 2008 Pearson Education, Inc. All rights reserved. 84 Outline XMLDOMTraversal.html (4 of 13) Insert three spaces for each level of indentation

 2008 Pearson Education, Inc. All rights reserved. 85 Outline XMLDOMTraversal.html (5 of 13) Check that the first child of the current node exists, then select and highlight it Select the next sibling of the current node, if it exists

 2008 Pearson Education, Inc. All rights reserved. 86 Outline XMLDOMTraversal.html (6 of 13) Check that the last child of the current node exists, then select and highlight it Select the previous sibling of the current node, if it exists

 2008 Pearson Education, Inc. All rights reserved. 87 Outline XMLDOMTraversal.html (7 of 13) Select the parent of the current node Method to highlight or remove highlighting from elements

 2008 Pearson Education, Inc. All rights reserved. 88 Outline XMLDOMTraversal.html (8 of 13)

 2008 Pearson Education, Inc. All rights reserved. 89 Outline XMLDOMTraversal.html (9 of 13)

 2008 Pearson Education, Inc. All rights reserved. 90 Outline XMLDOMTraversal.html (10 of 13)

 2008 Pearson Education, Inc. All rights reserved. 91 Outline XMLDOMTraversal.html (11 of 13)

 2008 Pearson Education, Inc. All rights reserved. 92 Outline XMLDOMTraversal.html (12 of 13)

 2008 Pearson Education, Inc. All rights reserved. 93 Outline XMLDOMTraversal.html (13 of 13)

 2008 Pearson Education, Inc. All rights reserved. 94 Common Programming Error 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.

 2008 Pearson Education, Inc. All rights reserved. 95 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.

 2008 Pearson Education, Inc. All rights reserved. 96 Fig | Common Node properties and methods. (Part 1 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 97 Fig | Common Node properties and methods. (Part 2 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 98 Fig | NodeList property and method.

 2008 Pearson Education, Inc. All rights reserved. 99 Fig | Document properties and methods.

 2008 Pearson Education, Inc. All rights reserved. 100 Fig | Element property and methods.

 2008 Pearson Education, Inc. All rights reserved. 101 Fig | Attr properties.

 2008 Pearson Education, Inc. All rights reserved. 102 Fig | Text methods.

 2008 Pearson Education, Inc. All rights reserved. 103 Outline xpath.html (1 of 5)

 2008 Pearson Education, Inc. All rights reserved. 104 Outline xpath.html (2 of 5)

 2008 Pearson Education, Inc. All rights reserved. 105 Outline xpath.html (3 of 5) IE7 uses the document object’s selectNodes method to select nodes using an XPath. Other browsers use the document object’s evaluate method.

 2008 Pearson Education, Inc. All rights reserved. 106 Outline xpath.html (4 of 5)

 2008 Pearson Education, Inc. All rights reserved. 107 Outline xpath.html (5 of 5)

 2008 Pearson Education, Inc. All rights reserved. 108 Outline sports.xml

 2008 Pearson Education, Inc. All rights reserved. 109 Fig | XPath expressions and descriptions.

 2008 Pearson Education, Inc. All rights reserved RSS RSS stands – RDF (Resource Description Framework) Site Summary – Also known as Rich Site Summary and Really Simple Syndication An XML format used to syndicate simple website content – news articles, blog entries, product reviews, podcasts, vodcasts and more RSS feed contains – rss root element with a version attribute – channel child element with item subelements – Depending on the RSS version, the channel and item elements have certain required and optional child elements item elements – provide the feed subscriber with a link to a web page or file, a title and description of the page or file Enables website developers to draw more traffic. Required child elements of channel in RSS 2.0 – Description – link – Title Required child elements of item in RSS 2.0 – title or description

 2008 Pearson Education, Inc. All rights reserved RSS (Cont.) RSS aggregator – keeps tracks of many RSS feeds – brings together information from the separate feeds Many sites provide RSS feed validators – validator.w3.org/feed – feedvalidator.org – The DOM and XSL can be used to create RSS aggregators A simple RSS aggregator uses an XSL style sheet to format RSS feeds as XHTML MSXML’s built-in XSLT capabilities include method transformNode to apply an XSLT transformation – Invoked on an RSS document object and receives the XSL document object as an argument Firefox provides built-in XSLT processing in the form of the XSLTProcessor object – After creating this object, use its importStylesheet method to specify the XSL style sheet you’d like to apply – Apply the transformation by invoking the XSLTProcessor object’s transformToFragment method, which returns a document fragment

 2008 Pearson Education, Inc. All rights reserved. 112 Fig | channel elements and descriptions. (Part 1 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 113 Fig | channel elements and descriptions. (Part 2 of 2.)

 2008 Pearson Education, Inc. All rights reserved. 114 Fig | item elements and descriptions.

 2008 Pearson Education, Inc. All rights reserved. 115 Outline RssViewer.html (1 of 5) Because of browser incompatibilities, our code needs to determine which browser it is running on.

 2008 Pearson Education, Inc. All rights reserved. 116 Outline RssViewer.html (2 of 5) IE7 downloads and loads the documents synchronously Firefox loads documents asynchronously, so use the onload event to make the events happen in the correct sequence

 2008 Pearson Education, Inc. All rights reserved. 117 Outline RssViewer.html (3 of 5)

 2008 Pearson Education, Inc. All rights reserved. 118 Outline RssViewer.html (4 of 5) Separate methods are used to apply the XSLT for IE and other browsers

 2008 Pearson Education, Inc. All rights reserved. 119 Outline RssViewer.html (5 of 5)

 2008 Pearson Education, Inc. All rights reserved. 120 Outline deitel-20.xml (1 of 2)

 2008 Pearson Education, Inc. All rights reserved. 121 Outline deitel-20.xml (2 of 2)