Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 64 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
64
Dung lượng
1,03 MB
Nội dung
Contents Overview 1 UsingMappingSchemas 2 UsingSchemas to Retrieve Data 11 Lab 6.1: UsingMappingSchemas 21 Mapping Multiple Tables 30 Lab 6.2: Mapping Multiple Tables 37 Annotating an Existing Schema 42 Lab 6.3: Annotating an Existing Schema 52 Best Practices 56 Review 57 Module6:UsingMappingSchemas Information in this document is subject to change without notice. The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted. Complying with all applicable copyright laws is the responsibility of the user. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation. If, however, your only means of access is electronic, permission to print one copy is hereby granted. 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, ActiveX, BackOffice, BizTalk, MSDN, MS-DOS, SQL Server, Visual Basic, Visual C++, Visual InterDev, Visual J++, Visual Studio, Windows, Windows Media, Windows NT, and Windows 2000 are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. Module6:UsingMappingSchemas iii Instructor Notes This module introduces students to the use of XML-Data Reduced (XDR) Schemas as mapping schemas, and discusses the main annotations the students will need in order to map an Extensible Markup Language (XML) document to data in a Microsoft ® SQL Server ™ database. After completing this module, students will be able to: Describe the uses and structure of annotated schemas. Create annotated schemas that map business documents to database entities. Use the XML Path Language (XPath) to access data through an annotated schema. Use Microsoft ActiveX ® Data Objects (ADO) to request data by using an annotated schema. Access data by using a schema over the Hypertext Transport Protocol (HTTP). Materials and Preparation This section provides the materials and preparation tasks that you need to teach this module. Required Materials To teach this module, you need the following materials: Microsoft PowerPoint ® file 2091a_06.ppt The XDR.xml example schema (for the demonstration) Preparation Tasks To prepare for this module, you should: Read all of the materials for this module. Complete the labs. Practice the demonstration. Presentation: 90 Minutes Lab: 90 Minutes iv Module6:UsingMappingSchemas Demonstration This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes. Creating an Annotated Schema To prepare for the demonstration 1. Follow the demonstration steps to create the schema. 2. Because the schema is based on data in the Northwind Traders database, you might want to extend the demonstration by publishing the schema in a virtual name and accessing data through it with Microsoft Internet Explorer. Module6:UsingMappingSchemas v Module Strategy Use the following strategies to present this module: UsingMappingSchemas This section sets the scene and explains why schemas are a good way to retrieve data. First, introduce schemas as a way of defining business documents to be exchanged between trading partners or applications. Then, describe how to create a default mapping between database entities and XML documents by using a mapping schema. Finally, emphasize that in most production environments, you will need to add annotations in order to map your business documents to database entities. UsingSchemas to Retrieve Data Explain that there are three basic ways to retrieve data with a schema: by using ADO, by referencing the schema in an XML template, and by publishing the schema in a virtual name. Regardless of which approach you take, you must use an XPath expression to define the rows you want to return. Mapping Multiple Tables Explain that this section presents a much more realistic use of mapping schemas, because most business data is stored in a relational format and normalized into multiple tables. Emphasize the importance of the sql:key- fields annotation, which ensures that the results are grouped correctly by identifying the primary key. Although not always required, you should encourage students to use the sql:key-fields annotation whenever they create a schema with a relationship annotation. Annotating an Existing Schema It is very likely that most mappingschemas in a business solution will be based on existing schemas rather than newly created schemas designed explicitly to map data. This section discusses the annotations that can be used to include non-mapped elements (such as the root element or collection elements) in a mapping schema. It is also worth pointing out that if the schema contains a root element annotated with the sql:is-constant annotation, you do not have to specify a root element when retrieving data because a well-formed document will be returned. Module6:UsingMappingSchemas 1 Overview UsingMappingSchemas UsingSchemas to Retrieve Data Mapping Multiple Tables Annotating an Existing Schema ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Mappingschemas are XML-Data Reduced (XDR) Schemas that specify the structure of an Extensible Markup Language (XML) document and map the elements and attributes it contains to tables and columns in a Microsoft ® SQL Server ™ database. After completing this module, you will be able to: • Describe the uses and structure of annotated schemas. • Create annotated schemas that map business documents to database entities. • Use the XML Path Language (XPath) to access data through an annotated schema. • Use Microsoft ActiveX ® Data Objects (ADO) to request data by using an annotated schema. • Access data by using a schema over the Hypertext Transport Protocol (HTTP). Topic Objective To provide an overview of the module topics and objectives. Lead-in In this module, you will learn how to use mappingschemas to retrieve XML data and map business document definitions to data in a SQL Server database. 2 Module6:UsingMappingSchemas UsingMappingSchemas UsingSchemas for Data Exchange Defining Business Documents UsingSchemas Defining a Default Table-to-Schema Mapping Adding Annotations to a Schema Demonstration: Creating an Annotated Schema ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** You can use XDR Schemas to define an XML representation of a specific business document. This type of schema is particularly useful when multiple organizations must exchange business documents by using XML, because an XDR Schema provides a way to agree on a document’s XML format. Later in this module, you will see how to use schemas to access data in SQL Server tables. For example, a retailer and a supplier could agree to use a schema to define a purchase order document that they will exchange. You use a mapping schema to associate a business document’s representation in XML with the underlying data in the database. You define the mapping by using table and column names to define XML elements and attributes. You can also use an annotated schema that contains annotations that map XML data to tables and columns in the database. You use an annotated schema to specify exactly which elements and attributes map to database tables and columns. In addition, you can specify XPath queries against the XML view by using the mapping schema to query the database. The result of this type of query is an XML document. This section discusses XDR Schemas and the creation of mapping schemas. Topic Objective To introduce the topics in this section. Lead-in In this section, we will examine how to map XDR Schemas to SQL data. Module6:UsingMappingSchemas 3 UsingSchemas for Data Exchange Supplier Purchase order Catalog Retailer Catalog schema Purchase order schema ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** When two organizations need to agree on the XML representation of a particular type of business document, they can define a schema. Defining Business Documents with SchemasSchemas are XML documents that define the elements and attributes that can be legally used in a particular class of XML document. Schemas are useful when two business partners need to agree on a common definition for a document they will exchange. For example, a retailer and a supplier might create a schema that defines a purchase order. Because there is an agreed definition of what a purchase order should look like, the two organizations can implement business processing logic to handle the purchase order documents that they will exchange. Similarly, a second schema could be used to define a catalog document, allowing catalog data to be exchanged in a consistent format. Mapping Data in Tables to XML with Schemas You can use XML schemas with SQL Server 2000 to map the data in XML business documents to data in the tables of a SQL Server database. This provides a way of generating XML business documents that contain data from SQL Server. Topic Objective To explain why schemas are useful for exchanging data. Lead-in Schemas are useful when two organizations need to agree on the XML representation of a business document. Delivery Tip This slide builds automatically. First, the slide shows a purchase order schema being used as an agreed definition for XML purchase orders that a retailer will send to a supplier. Then, it shows a catalog schema being used as an agreed definition for a catalog document that will be downloaded from the supplier. You can restart the build by pressing the LEFT ARROW key on the keyboard. 4 Module6:UsingMappingSchemas Defining Business Documents UsingSchemas Agree on an XML representation of the document Create an XML-Data Reduced (XDR) schema Reference namespaces for element, attribute, and data types Define valid elements and attributes ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** You can use schemas to define an XML document’s structure. The ability to define a valid XML representation of a business document is particularly important when instances of the document must be exchanged between systems and organizations. Agreeing on an XML Representation of the Document When two organizations or applications must exchange a business document such as a purchase order or invoice, they must agree on a common definition of a valid instance of that document. Consider the following issues when agreeing on the definition of an XML representation of a business document: Which elements and attributes can be included in the document? Which elements or attributes are mandatory, and which are optional? How many instances of each element in the document are allowed? What data types must the values in the elements and attributes be? You can define the agreement in an XDR Schema, which is an XML document that contains the definition for a particular type of business document. Creating an XDR Schema XDR Schemas commonly use two namespaces, as described in the following table. Namespace Description urn:schemas-microsoft-com:xml-data Defines XDR elements and attributes. urn:schemas-microsoft-com:datatypes Defines data types for elements and attributes. Topic Objective To describe how to use an XDR Schema to define the XML representation of a business document. Lead-in XDR provides a way to define the structure of an XML document: its elements and attributes and their types. Delivery Tip It is assumed that the students are already familiar with XDR syntax. Therefore, the XDR elements are not explained in detail at this time. [...]... Caching of MappingSchemas To disable caching when using ADO, set the SS STREAM FLAGS property to STREAM_FLAGS_DONTCACHESMAPPINGCHEMA (8) as shown in the following example: objCmd.Properties("SS STREAM FLAGS") = 8 Module6:UsingMappingSchemas 21 Lab 6.1: UsingMappingSchemas Topic Objective To introduce the lab Lead-in In this lab, you will create a simple mapping schema and generate XML documents... document and generate XML documents from the schema in various ways Estimated time to complete this lab: 30 minutes Module6:UsingMappingSchemas 23 Exercise 1 Creating a Simple Mapping Schema In this exercise, you will add annotations to an existing XDR Schema in order to create a simple mapping schema You will use a previously written test framework that will generate an XML document from the mapping. .. xmlns:sql="urn :schemas- microsoft-com:xml-sql"> /Invoice Module6:UsingMappingSchemas Delivery Tip Compare this process to the process of creating SQLbased templates, which was covered in Module 5, Using HTTP to Access XML Data.” Delivery Tip The parameter-passing mechanism is similar to SQL-based templates, described in Module. .. find a reference for XDR Schemas at http://msdn.microsoft.com/xml/reference/schema/start.asp 5 6 Module6:UsingMappingSchemas Defining a Default Table-to-Schema Mapping Topic Objective To explain the default mappings between the database and XML elements in the schema Lead-in XDR Schemas can be mapped to data in a SQL Server database The SQLOLEDB Provider recognizes a default mapping between a schema... Exchanging and Transforming Data Using XML and XSLT, Module 2, “Selecting and Navigating Nodes Using XPath.” You can specify XPath expressions in several ways, such as by using a URL, a template, or programmatically through ADO These techniques will be discussed later in this module This section illustrates the syntax and semantics of XPath queries Module 6:UsingMappingSchemas For example, assume that... area at the bottom of the screen (You may paste the generated document into a new file and load it into Internet Explorer to view the results more clearly) Module 6:UsingMappingSchemas 25 Exercise 2 Using ADO to Create XML Documents In this exercise, you will write an application that uses ADO to create an XML document from a given mapping schema, database, and XPath expression Scenario The business... resemble the following: http://localhost/Lab06 /schemas/ ProductSchema1.xml /Product[@Discontinued=1]?root=Catalog 30 Module6:UsingMappingSchemasMapping Multiple Tables Topic Objective To introduce the topics in this section Lead-in In this section, we will discuss how to map schemas to multiple database tables Mapping Related Tables Controlling XML Document Nesting Filtering Data *****************************ILLEGAL... http://webserver/retaildata/templates/order.xml?OrderID=1907 18 Module6:UsingMappingSchemas Publishing a Schema Virtual Name Topic Objective To describe how to create and use virtual names for schemas Lead-in You save schema files in a folder that is configured as a virtual name Folders containing schemas are configured as virtual names Webserver C:\SQLSite (Virtual root data) C: \Schemas (Virtual name schemas) inv.xml Client applications... element.) The following example retrieves an XML document from the webserver server through the virtual root “query”, which has the virtual name schemas for schemas The schema file name is inv.xml, the XPath expression is Item, and the name of the root element is Invoice Example http://webserver/query /schemas/ inv.xml/Item?root=Invoice 20 Module6:UsingMappingSchemas Controlling Schema Caching Topic Objective... demonstration, you will see how to create a simple annotated schema Module 6:UsingMappingSchemas 11 UsingSchemas to Retrieve Data Topic Objective To introduce the topics in this section Lead-in In this section, we will examine how client applications can retrieve XML data by using a schema Specifying Data with an XPath Expression Using a Schema with an ADO Command Object Querying a Schema from a . database. 2 Module 6: Using Mapping Schemas Using Mapping Schemas Using Schemas for Data Exchange Defining Business Documents Using Schemas . well-formed document will be returned. Module 6: Using Mapping Schemas 1 Overview Using Mapping Schemas Using Schemas to Retrieve Data Mapping Multiple