Tài liệu Module 4: Technologies for Handling XML Data pdf

20 497 0
Tài liệu Module 4: Technologies for Handling XML Data pdf

Đ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

Contents Overview 1 Lesson: Metadata and XML Processing 2 Lesson: XML Processing Technologies 6 Module 4: Technologies for Handling XML Data Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, places or events is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.  2001 Microsoft Corporation. All rights reserved. Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BackOffice, bCentral, BizTalk, FrontPage, MSDN, MSN, Netshow, PowerPoint, SharePoint, Visio, Visual Basic, Visual C++, Visual C#, Visual InterDev, Visual Studio, Windows Media, and Xbox are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Module 4: Technologies for Handling XML Data iii Instructor Notes After completing this module, participants will be able to: ! Identify the appropriate technology for the task that requires them to manipulate Extensible Markup Language (XML) data. ! Explain the range of use for the Document Object Model (DOM), XML Path Language (XPath), Extensible Stylesheet Language (XSL), Extensible Stylesheet Language Transformations (XSLT), and XQuery. Materials and Preparation This section provides the materials and preparation tasks that you need to teach this module. To teach this module, you need the following materials: • Microsoft ® PowerPoint ® file 2500A_04.ppt To prepare for this module: ! Read all of the materials for this module. ! Read the modules on DOM, XPath, XSL and XSLT, and XQuery. ! Be ready to compare and contrast the uses of the technologies that are discussed in this chapter. Presentation: 45 Minutes Required Materials Preparation Tasks iv Module 4: Technologies for Handling XML Data Module Strategy This is an overview module. The instructional strategy depends on the quality of your lecture. Be prepared to carefully and quickly explain the ideas presented here. You have less than an hour to complete this module, so present each slide without lingering on any particular topic. The modules that follow this one discuss each issue in more depth. Use the following strategy to present this module: ! Metadata and XML Processing A major source of confusion to participants is why object models are needed to describe XML. This lesson describes situations that require some application logic to perform a query. The lesson says that the DOM and XPath object models create a metadata structure. Applications require metadata to perform sophisticated operations. Metadata is a term that is often used but not often readily understood. Be sure that participants understand this term, because understanding metadata is critical to appreciating the role XML plays in building data-centric applications. Use the idea of metadata to explain why both DOM and XPath use a tree of nodes to represent XML data. ! XML Processing Technologies The profusion of XML technologies that exist can be confusing to the newcomer. This lesson helps the participant by providing an overview of the major technologies. Briefly define DOM. A very simple XML fragment in the text illustrates why you must search XML by using node properties instead of a simple text search. Briefly define XPath. XPath is defined here as an object model optimized for specifying location information. Contrast the functionality of XPath with that of DOM. Stress that XPath is central to using the other XML technologies. Define XQuery as a comprehensive and ambitious query technology. Provide a basic definition of XSL. This lesson defines XSL as the formatting language for XML. It discusses XSLT and XSL-FO as specialty subset languages within XSL. XSL-FO is not discussed any further in the course, because at the time of publication, it is not widely adopted. It is not a World Wide Web Consortium (W3C) Recommendation. Module 4: Technologies for Handling XML Data 1 Overview ! Metadata and XML Processing ! XML Processing Technologies ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** This module describes several interdependent technologies. You use them to: ! Query an Extensible Markup Language (XML) document. ! Change the content of an XML document. ! Change the structure of an XML document. This module will help you choose which technologies to apply in different circumstances. After completing this module, you will be able to: ! Identify the appropriate technology for the task that requires you to manipulate XML data. ! Explain the range of use for the Document Object Model (DOM), XML Path Language (XPath), Extensible Stylesheet Language (XSL), Extensible Stylesheet Language Transformations (XSLT), and XQuery. Introduction Objectives 2 Module 4: Technologies for Handling XML Data Lesson: Metadata and XML Processing ! What Is XML Metadata? ! How to Use XML Metadata ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** This lesson presents the main technologies for handling XML data. After completing this lesson, you will be able to: ! Define metadata, tree, and node. ! Explain why you need metadata to process XML. Introduction Lesson ob jectives Module 4: Technologies for Handling XML Data 3 What Is XML Metadata? ! Metadata is data about data ! Humans use lexical metadata to understand the markup " Consists of the meaning of the element and attribute names ! Software uses structural metadata " Consists of the element hierarchy and the presence of attributes, comments, or CDATA sections ! DOM and XPath model structural metadata as a tree ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Metadata is a general computing term that means data about data. Consider a recipe for making French bread that is written on an index card. The data is the recipe. The metadata is the name of the person who wrote the recipe on the index card, where the card is located, or any other information about the recipe. If the recipe is in a text file instead of written on an index card, then the metadata is the recipe’s file name, the date the file was created, the size of the file on the disk, and whether it is marked as read-only. The metadata in this case provides the operating system with the information required to find the file, sort the file in a list, and so on. There are two ways of looking at metadata in XML. The names of elements and attributes can be viewed as metadata, because most often they describe their contents. The lexical metadata inherent in element and attribute names allows developers to understand some of the meaning of the data by reading the markup. Many of the structural aspects of XML can be useful as metadata. Structural metadata is useful for exercising programmatic control over XML. For example, the hierarchical structure of XML can be useful for establishing the coordinates of a piece of data located deep within a large XML hierarchy. You can use the fact that a certain attribute only occurs in elements three levels down from the root element. Whether attributes, processing instructions, character data (CDATA) sections, or comments are present or not can also be a useful form of structural metadata. For example, you can program an application to use data encoded in XML processing instructions, or you can put very long sections of code in CDATA sections. Attributes can contain information about namespaces. Any of these structural features can be used to develop a schema. Solutions built using XML technologies rely on structural metadata in many ways to exercise programmatic control over XML. Introduction Lexical XML metadata Structural XML metadata 4 Module 4: Technologies for Handling XML Data DOM and XPath both process XML by creating a tree representation of its structural metadata. The structural metadata is represented as a tree of nodes. Modeling XML data as a tree of nodes creates groups of related data that you can use to efficiently locate, query, and change specific content. DOM and XPath: XML metadata as a tree Module 4: Technologies for Handling XML Data 5 How to Use XML Metadata Document Node Document Node Element Node Element Node Element Node Element Node Text Character Node Text Character Node <Photographs> <Photograph ID="3"> <FilmID>1</FilmID> <PhotoLocationID>1</PhotoLocationID> <PhotographNumber>3</PhotographNumber> <DateTaken>12/15/1999</DateTaken> <TimeTaken></TimeTaken> <PlaceTaken>Louvre</PlaceTaken> <SubjectName>Dad</SubjectName> <SubjectPhone></SubjectPhone> <LensUsed></LensUsed> <Aperture></Aperture> <ShutterSpeed></ShutterSpeed> <FilterUsed></FilterUsed> <Flash>False</Flash> <PrintSize></PrintSize> . <Photographs> <Photograph ID="3"> <FilmID>1</FilmID> <PhotoLocationID>1</PhotoLocationID> <PhotographNumber>3</PhotographNumber> <DateTaken>12/15/1999</DateTaken> <TimeTaken></TimeTaken> <PlaceTaken>Louvre</PlaceTaken> <SubjectName>Dad</SubjectName> <SubjectPhone></SubjectPhone> <LensUsed></LensUsed> <Aperture></Aperture> <ShutterSpeed></ShutterSpeed> <FilterUsed></FilterUsed> <Flash>False</Flash> <PrintSize></PrintSize> . XML Source Document XML Source Document XML Metadata XML Metadata XML Model XML Model RESULT SET: <Photograph ID="341"><ShutterSpeed>2000</ShutterSpeed></Photograph> <Photograph ID="1025"><PlaceTaken>Ocean Shores</PlaceTaken> <ShutterSpeed>10000</ShutterSpeed> </Photograph> RESULT SET: <Photograph ID="341"><ShutterSpeed>2000</ShutterSpeed></Photograph> <Photograph ID="1025"><PlaceTaken>Ocean Shores</PlaceTaken> <ShutterSpeed>10000</ShutterSpeed> </Photograph> <Photographs> <Photograph> <ShutterSpeed> values QUERY: Get photos with shutter speed >= 2000 QUERY: Get photos with shutter speed >= 2000 ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** The illustration in the slide shows how you may use XML metadata to do something useful with XML data. The XML source document is a listing of photographs. The document element is named <Photographs>. The data for individual photographs is marked within <Photograph> elements. For example, each <Photograph> element has one element named <ShutterSpeed>. Suppose you are interested in finding all photographs with fast shutter speeds. You can examine each of the <ShutterSpeed> elements individually, looking for a value that is greater than 2000, which here means 1/2000 of a second. You can also use the XML metadata. You can use DOM or XPath to write a simple query that returns all records that meet your criteria. To query or manipulate an XML source, you must invoke an abstract model of the XML. The XML Document Object Model (DOM) specifies an abstract model of XML as a set of objects. The objects are arranged in an inverted tree with the document root at the top. XPath also models XML as a tree of nodes. Each node belongs to one data type or another. You can query an XML data source efficiently after it is formed into an abstract XML model. Introduction XML model 6 Module 4: Technologies for Handling XML Data Lesson: XML Processing Technologies ! What Is the XML Document Object Model? ! What Is XPath? ! What Is XQuery ! What Is XSL? ! What Is XSLT? ! How Are XSLT and XPath Related? ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** This lesson presents the main technologies for handling XML data. After completing this lesson, you will be able to: ! Define DOM, XPath, XQuery, XSL, and XSLT ! State which technology is used for which data-handling task. Introduction Lesson ob jectives [...]... used with other XML technologies XPath is integral to XSLT and XQuery XPath provides a means by which applications can navigate through patterns of XML and find specific content by using XML metadata modeled after a tree of nodes 14 Module 4: Technologies for Handling XML Data What Is XSLT? ! XSLT is the W3C XSL Transformations language ! Used with XPath ! Use it to transform format and XML vocabularies... name in the inventory Note For more information about XPath, see the W3C XPath 2.0 Recommendation at http://www.w3.org/TR/xpath Module 4: Technologies for Handling XML Data 11 What Is XQuery? ! XQuery is the W3C XML Query Language { FOR $b IN document("www.nwtraders.com/bib .xml" ) { FOR $b IN document("www.nwtraders.com/bib .xml" ) " Designed to query multiple XML sources //book[pub =.. .Module 4: Technologies for Handling XML Data 7 What Is the XML Document Object Model? ! DOM is the W3C programming interface for XML ! DOM models an XML source as a tree of nodes in memory ! You can use DOM to: " Navigate and search " Add and delete content City .xml City .xml Svolvaer City .xml in memory City .xml in memory Document Root... and other applications When used to transform XML, XSLT is very powerful You can use it to change XML vocabulary and structure and to perform conditional processing on XML When used to format XML, XSLT is a simpler language to use than XSL-FO, but its ability to format XML is less robust When used to format XML, XSLT is an XML- based alternative to formatting XML by using cascading style sheets Although... One XML vocabulary into another XML XML HTML HTML XML into HTML or text *****************************ILLEGAL FOR NON-TRAINER USE****************************** Introduction XSLT is short for Extensible Stylesheet Language Transformations You can use XSLT to transform XML into a different vocabulary and other data formats For example, you can use XSLT to transform XML into Hypertext Markup... resulted in three language Recommendations: XSL-FO XSL Formatting Objects XSLT XSL Transforms XPath XML Path Language Formatting Formatting Transforming and formatting Transforming and formatting Addressing parts of XML Addressing parts of XML *****************************ILLEGAL FOR NON-TRAINER USE****************************** Introduction XSL stands for Extensible Stylesheet Language, which is something... from different sources into one result set and then performs some function, such as average or count, on the result set 12 Module 4: Technologies for Handling XML Data Example The following code shows a segment of XQuery code that lists book information by publisher and the year of publication { FOR $b IN document("www.nwtraders.com/bib .xml" ) //book[pub = "Contoso Ltd" AND @year > "2001"] RETURN... Note For more information on XQuery, see the XQuery 1.0 Working Draft at http://www.w3.org/TR/xquery/ Practice What does each of the following XQuery and XPath expressions do? Expression { FOR $b IN document("www.nwtraders.com/bib .xml" ) //book[pub = "Contoso Ltd" AND @year > "2001"] { $b/@year } { $b/title } SORTBY (title)} What does it do? Module 4: Technologies for Handling XML Data 13 What... is written for DOM must be compiled in a specific programming language As a result, the query might not be portable Recognizing these limitations, the W3C created a query language specification for XML called XPath XPath greatly simplifies XML query statements so that they are easier to read You can easily port an XPath query to different systems Module 4: Technologies for Handling XML Data 9 What... the application with the occurrence of the element nested within the element 8 Module 4: Technologies for Handling XML Data How DOM works Your application uses DOM methods to create a representation in memory of an XML source document DOM represents XML in memory as a tree of node types For example, DOM maps the document element to a node called DocumentNode and sets the value of this . Objectives 2 Module 4: Technologies for Handling XML Data Lesson: Metadata and XML Processing ! What Is XML Metadata? ! How to Use XML Metadata *****************************. Overview 1 Lesson: Metadata and XML Processing 2 Lesson: XML Processing Technologies 6 Module 4: Technologies for Handling XML Data Information in this document,

Ngày đăng: 10/12/2013, 16:15

Từ khóa liên quan

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

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

Tài liệu liên quan