Contents Overview 1 Lesson: Metadata and XML Processing 2 Lesson: XML Processing Technologies 6 Module 4: Technologies for Handling XML Data... Explain the range of use for the Docume
Trang 1Contents
Overview 1
Lesson: Metadata and XML Processing 2
Lesson: XML Processing Technologies 6
Module 4: Technologies for Handling XML Data
Trang 2Information 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
Trang 3Instructor 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
Trang 4Module 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
Trang 5Overview
! 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
Trang 6Lesson: 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 objectives
Trang 7What 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
Trang 8DOM 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
Trang 9How to Use XML Metadata
Document Node Element Node Element 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>
<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>
<ShutterSpeed></ShutterSpeed>
<FilterUsed></FilterUsed>
<Flash>False</Flash>
<PrintSize></PrintSize>
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
Trang 10Lesson: 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 objectives
Trang 11What Is the XML Document Object Model?
City.xml in memory
! 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>
<name elev="9M">Svolvaer</name>
</city>
DocumentNode
AttrNode Element Node
Document Root
<city>
Element Node
<name> elev=“9M”
TextCharacterData
Svolvaer
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
The XML DOM provides a programming interface for applications to manipulate XML The W3C specification DOM Level 1 defines the properties, methods, and events of DOM
To use DOM, you must write a custom application Microsoft® XML Core Services (MSXML) and Microsoft Visual Studio® NET fully support the W3C standard and provide additional features that make it easier to program
applications to work with XML files
After an XML document is loaded into memory, the application can use DOM to:
! Search for specific content
! Add, remove, or replace content
! Save the result to an XML file
Consider the following XML document, which represents a purchase order It might have several <date> elements, each appearing in a different part of the document
<order>
<date>01.01.03</date>
<item>canvas</item>
<reorder>
<date>01.07.03</date>
<item>linen</item>
</reorder>
</order>
If you need to program an application to find the reorder date, it is helpful to provide the application with the occurrence of the <date> element nested within the <reorder> element
Introduction
Why use DOM?
Trang 12Your 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 to the name of the document element Applications that use DOM are programmed to recognize specific node types, such as the document element and content
DOM is not well-suited to processing large XML files Converting a large XML data source into memory causes some systems to slow down or to stop altogether To query a large XML document, you program your application to use another programming interface, such as the Simple Application
Programming Interface for XML (SAX) or XMLReader
DOM is not well-suited to changing XML structure If you want to convert an XML document to another vocabulary, you use XSLT instead of DOM Code that implements DOM can be difficult to write and to read A query that 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
How DOM works
Limitations of DOM