Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 62 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
62
Dung lượng
0,99 MB
Nội dung
Contents Overview 1 Preparing XMLData on the Client 2 PostingDatato the Server 11 Lab 7.1: Sending XML Packets to the Server 16 DOM Manipulation on the Server 24 Receiving the Response on the Client 36 Lab 7.2: Processing XML Packets at the Server 42 Review 54 Module7:PostingXMLDatafromClienttoServer 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. 2000 Microsoft Corporation. All rights reserved. Microsoft, PowerPoint, Visual InterDev, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. 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. Other product and company names mentioned herein may be the trademarks of their respective owners. Program Manager: Steve Merrill Instructional Designers: Sangeeta Nair (NIIT), Vijayalakshmi Narayanaswamy (NIIT) Subject Matter Experts: Andy Olsen (QA Training), Andy Longshaw (Content Masters) Content Lead: Janet Robinson Graphic Artist: Scott Serna (Creative Assets) Media Management: David Mahlmann Media Production: Dean Connolly (Art Source), Timothy Demmon (:timebomb Media) Editing Manager: Jennifer Linn Editor: Dennis Rae (Wasser) Production Manager: Miracle Davis Print Coordinator: Marlene Lambert (Online Training Solutions, Inc) Build Manager: Julie Challenger Build Coordinator: Jenny Boe Test Lead: Eric Myers Manufacturing Manager: John Williams Group Product Manager: Steve Elston Module7:PostingXMLDatafromClienttoServer iii Instructor Notes Prior to this module we have shown how to deliver XML content from the Web serverto the browser, and how to manipulate XMLdata on the browser. This module shows how to submit XMLdata in the opposite direction, that is, from browser to Web server. The module describes the benefits of postingXMLdata as opposed to any other format of data, and shows how the XMLHTTP object can be used to achieve this. The module also shows how the server receives this data and loads it into a server-side XMLDOM object. This is the first time students have seen that you can use DOM on the server — all previous examples of DOM have been client- side. It’s worthwhile to mention that it is the same object model, so you can do anything at the server that you can do at the browser. The module concludes by describing how the Web server can send an HTML or XML response back to the client, and how the client picks up this response. After completing this module, students will be able to: ! Describe the issues involved in creating an XMLdata packet to send to a server. ! Use the XMLHTTP object to send data back to the server. ! Convert XML into a server-side DOM tree. ! Update the back-end database with datafrom the client. ! Issue a response from the serverto the client. Materials and Preparation This section provides you with the required 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 1905a_07.ppt ! Module 7, “Posting XMLDatafromClientto Server” ! Lab 7.1, “Sending XML Packets to the Server” ! Lab 7.2, “Processing XML Packets at the Server” Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module. ! Complete the labs. Due to the length of the answers to the labs for this course, we were unable to include them in the Delivery Guide. Please see Appendix A and the Student CD for the lab answers. Presentation: 120 Minutes Lab 7.1 45 Minutes Lab 7.2 30 Minutes iv Module7:PostingXMLDatafromClienttoServer Demonstrations This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes. Handling responses on the client ! Discuss the code in ResponseXML.htm 1. In Notepad, open ResponseXML.htm. 2. Move to the end of ResponseXML.htm and point out the three BUTTON elements. Each button has a different onclick event procedure. 3. Move to the beginning of ResponseXML.htm and briefly show the three onclick event procedures. Note that each calls the same procedure, prepareToPost. 4. Examine the prepareToPost procedure in detail. It begins with some boilerplate XML, and then adds new XML content for the customer ID (as entered by the user). The code then clones an existing XMLdata island (located near the end of the HTM page) and adds this to the XMLdata packet as well. 5. Reexamine the event procedures responseStr_OnClick, responseHTML_OnClick, and responseXML_OnClick. Each procedure submits the XMLdata packet to a different ASP page. ! Discuss the code in the ASPs 1. In Notepad, open CustOrderStr.asp. This ASP page returns simple text. 2. In Notepad, open CustOrderHTML.asp. This ASP page returns HTML content. 3. In Notepad, open CustOrderXML.asp. This ASP page creates an XMLDOM object, loads the XML sent from the browser, and returns the same XML back to the browser. Note that the Response.ContentType must be set to “text/xml” first. ! Add code to ResponseXML.htm to handle ASP responses 1. In Notepad, open ResponseXML.htm. 2. Add code to the event procedures to show the string/HTML/XML response from the various ASPs: a. Add the following script to responseStr_OnClick to display the response from the server: MsgBox poster.responseText, , "Response from Server" b. Add the following script to responseHTML_OnClick to display the response from the server: MsgBox poster.responseText, , "Response from Server" c. Add the following script to responseXML_OnClick to display the response from the server: MsgBox poster.responseXML.xml, , "Response from Server" Module7:PostingXMLDatafromClienttoServer v Module Strategy Use the following strategies to present this module: ! Preparing XMLData on the Client In this section, begin by reviewing how XMLdata is sent from the Web serverto the client, and discuss the benefits of delivering XML rather than HTML. Briefly introduce the XMLHTTP object and discuss how it orchestrates the transmission of XMLdatafrom the clientto the server. Then describe how the server loads the XMLdata into a server-side XMLDOM object in order to process that data on the server. It’s worthwhile to describe how the client builds the XMLdata packet, ready to send to the server. In particular, describe how the clone method is used to clone datafrom another XML document (or data island) and merge it with the XML document being sent to the server. If you don’t use the clone method, the XMLdata will be removed from the original DOM tree and added into the new one. ! PostingDatato the Server This brief section describes how to use the XMLHTTP object to send XMLdatafrom the clientto the server. Point out that the data can be sent synchronously (the client waits for a response from the server before continuing processing) or asynchronously (the client continues processing without waiting for a response). ! Lab 7.1: Sending XML Packets to the Server In this lab, students complete the Go to Checkout functionality in an HTML file named Checkout.htm. An XMLdata packet is assembled from the orders data island, together with information about the customer. An XMLHTTP object is then created, and the XMLdata packet is posted to an ASP page named CustomerOrder.asp. The ASP page doesn’t do much at the moment — that’s the subject of Lab 7.2. ! DOM Manipulation on the Server There are two main points to emphasize here: First, the ASP page receiving a request that contains XMLdata creates an XMLDOM object to hold the XMLdatafrom the client; second, this XMLDOM object has the same DOM programming interface as on the client. Therefore, the same capabilities exist for server-side XMLdata manipulation. Also observe that the server can issue any type of response back to the client, such as plain text, an HTML page, or more XMLdata (either a static XML document or dynamically-generated XML data). ! Receiving the Response on the Client This section describes how the client picks up different types of responses from the server. The demonstration illustrates how to handle a plain text response, an HTML response, and an XML response. vi Module7:PostingXMLDatafromClienttoServer ! Lab 7.2: Processing XML Packets at the Server This lab modifies CustomerOrder.asp to perform intelligent processing when it receives an XMLdata packet from the client. The ASP page updates various tables in the LitWare Books database, and then issues an HTML response back to the client. (One of the optional exercises returns an XML response instead.) Note that all the SQL statements required in this lab have already been provided in starter files, to save time for the students and to focus on XML issues rather than SQL. Module7:PostingXMLDatafromClienttoServer 1 # ## # Overview ! Preparing XMLData on the Client ! PostingDatato the Server ! Lab 7.1: Sending XML Packets to the Server ! DOM Manipulation on the Server ! Receiving the Response on the Client ! Lab 7.2: Processing XML Packets at the Server ! Review In this module, you will learn how to post XMLdatafrom the clientto the server. You will also learn how the server picks up the XMLdata and sends a suitable response back to the client. After completing this module, you will be able to: ! Describe the issues involved in creating an XMLdata packet to send to a server. ! Use the XMLHTTP object to send data back to the server. ! Convert XML into a server-side DOM tree. ! Update the back-end database with datafrom the client. ! Issue a response from the serverto the client. Slide Objective To provide an overview of the module topics and objectives. Lead-in In this module, you will learn about the process of sending updated XMLdata back to the server. You will also learn how the server responds when receiving the data. 2 Module7:PostingXMLDatafromClienttoServer # ## # Preparing XMLData on the Client ! Client/Server XML Application Architecture ! Sending XMLDatafromClienttoServer ! Building an XMLData Packet ! Populating an XMLData Packet ! Demonstration: Preparing XMLData on the Client This section describes the traditional Get/Post feedback techniques used with Web servers. It also explains why XML and related technologies are used instead of the common practice of using ADO on the server, RDS on the client, and feedback via forms, and so on. Slide Objective To provide an overview of the topics in this section. Lead-in Conventional client-to-Web serverdata transfer uses Post/Get HTTP methods. This section introduces techniques specific topostingXMLdatafrom the clientto the server. Module7:PostingXMLDatafromClienttoServer 3 Client/Server XML Application Architecture ! Use XMLto communicate between client and server $ Server sends XMLto the client $ Client sends XML back to the serverClientData sourceWeb server Order info XML Catalog XML Read catalog Update database Build XMLdata packet 12 4 5 3 Thus far, all of the data flow we have discussed has been from the Web serverto the client. We have examined how XMLdata can be used to represent the information sent from the serverto the client. It is also possible for the clientto send XML information back to the server, for example, a list of items in a shopping basket. A traditional Web application might send small updates to the server as each individual item is added to the shopping basket. This method is rather inefficient in its use of network and server resources. It would be far more efficient to cache all the information on the client and then send it to the server in a single batch. In this way, additions and alterations to the pending updates would occur only on the client, without involving the network or server. Using XMLdatato transfer information enables you to cache all data on the client and send only the updates to the server. The preceding illustration shows a typical interaction between a Web server and a client, using XMLdatato relay information in both directions: 1. The Web server reads information from a data source, for example, a catalog of books in a bookstore database. 2. The Web server builds an XML document from this data and sends the XMLto the client. 3. The client builds an XMLdata packet, for example, a list of books the user would like to order from the catalog. 4. The client sends the XMLdata packet to the Web server when required. 5. The Web server receives the XMLdata packet from the client and processes the data appropriately. For example, the Web server might update the OrderItems table in the bookstore database. Slide Objective To revisit the architecture of an XML client/server application. Lead-in In previous modules, we discussed topics and concepts that have pieced together an architecture for a client/server XML application. Now we will discuss how to post XMLdata back to the server. Delivery Tip The slide is animated so that it shows only the Client, Web server, and Data source boxes initially. Click the slide to reveal the following additional parts of the illustration: 1. Shows the arrow, text, and label “1” for data being read from the data source to the Web server. 2. Shows the arrow, text, and label “2” for XMLdata being sent to the client. 3. Shows the arrow, text, and label “3” for the XMLdata packet being built at the client. 4. Shows the arrow, text, and label “4” for the XMLdata packet being sent to the server. 5. Shows the arrow, text, and label “5” for database updates being sent to the data source. 4 Module7:PostingXMLDatafromClienttoServer Sending XMLDatafromClienttoServer ! Client creates an XMLdata packet and posts it to the serverClient Web serverXML DOM tree 1 XMLHTTP object 2 XMLDOM object 4 XML DOM tree 6 3 5 The preceding illustration shows the steps involved in building an XMLdata packet on the client and then posting it to the Web server. The illustration also shows how to pick up the XMLdata packet at the Web server and perform appropriate server-side processing based on the contents of the data. Let’s consider each of the following steps: 1. The client populates an XMLDOM object with XMLdatato send to the Web server. 2. The client creates an XMLHTTP object. This object has various methods and properties that are used to send the XMLdatato an application (for example, an ASP page) at the Web server and receive a response. 3. The client loads the XMLdata packet into the XMLHTTP object, and then sends the datato the ASP page at the Web server. 4. The Web server executes the ASP page. The ASP creates a server-side XMLDOM object that is ready to receive the XMLdatafrom the client. 5. The ASP loads the XMLdata packet into the XMLDOM object at the server. 6. The ASP processes the XMLdata appropriately. For example, it stores the data in the database. Slide Objective To illustrate the steps involved in building an XMLdata packet at the client and posting it to the server. Lead-in Let’s consider the steps involved in building an XMLdata packet at the client, posting it to the server, and then processing the data when it is received at the server. Delivery Tip The slide is animated so that it shows only the Client and Web server boxes initially. Click the slide to reveal the following additional parts of the illustration: 1. Shows the arrow and label “1” for creating the XMLdata packet. 2. Shows the arrow and label “2” for creating the XMLHTTP object. 3. Shows the arrow and label “3” for posting the XMLdata packet to the server. 4. Shows label “4” for creating the XMLDOM object on the server. 5. Shows the arrow and label “5” for loading the XMLdata packet into the XMLDOM object on the server. 6. Shows the arrow and label “6” for performing appropriate server-side processing based on the contents of the XMLdata packet. [...]... Module7: Posting XMLDatafromClienttoServer Demonstration: Preparing XMLData on the Client Slide Objective To demonstrate how to create an XMLdata packet that is ready to be sent to a Web server Lead-in In this demonstration, you will learn how to create an XMLDOM object on the client and populate it with a mixture of boilerplate XML data, XMLdatafrom a data island, and XML data. .. load the XMLdatafrom the client You will also see how the server can use the datato perform back-end processing, such as updating database tables Module 7:PostingXMLDatafromClienttoServer 25 Loading XMLData on the Server Slide Objective To create an XMLDOM object on the server ! Load the XMLdatafrom the Request object ! When the client posts XMLdatato an ASP at the server, the server must... boilerplate XML document: < ?xml version='1.0'?> 5 The root element of the XML document is You can now add existing XMLdata into this DOM tree, after the element Module 7:PostingXMLDatafromClienttoServer Populating an XMLData Packet Slide Objective To populate an XMLdata packet with information fromXMLdata islands.. .Module 7:PostingXMLDatafromClienttoServer 5 Building an XMLData Packet Slide Objective To introduce the tasks required to package the data that is to be sent back to the server ! Create an XMLDOM object Set docSubmit = CreateObject("Microsoft.XMLDOM") Set docSubmit = CreateObject("Microsoft.XMLDOM") Lead-in Let’s consider how the client prepares the XMLdatato be sent back to the Web server. .. Microsoft.XMLHTTP, which is used as a request object to transport XMLdatato the Web server 12 Module7: Posting XMLDatafromClienttoServer Instantiating the XMLHTTP Object Slide Objective To create and use an XMLHTTP object ! Lead-in To post XMLdatato the Web server, you must first create a COM object named XMLHTTP that provides methods and properties for sending the data Create a Microsoft.XMLHTTP... connection to post data, asynchronously, to the CustomerOrder.asp page: poster.open "POST", "CustomerOrder.asp", False 13 14 Module7: Posting XMLDatafromClienttoServer Sending Datato the Server Slide Objective To introduce the send method of XMLHTTP Request ! Lead-in Send the XMLdata $ Once the XMLHTTP object has been created and opened, the next step is to send the datato the server by using... following illustration Module 7:PostingXMLDatafromClienttoServer 21 Exercise 3: Posting the XMLData Packet to the Web Server In this exercise, you will create an XMLHTTP object and use it to post the XMLdata packet to the Web server You will then create a new ASP page, CustomerOrder.asp, to receive the XMLdata packet at the Web server and acknowledge receipt of the data with a simple response... boilerplate XML document, the next step is to populate the document with the data you wish to send to the Web server Typically, the XMLdata packet includes a mixture of content: ! XMLdata created from user input ! XMLdata retrieved fromXMLdata islands or XML documents Creating XMLdatafrom user input Frequently you will have user input that you need to merge into the XMLdata before sending the XML to. .. DOM.” 26 Module7: Posting XMLDatafromClienttoServer For example, the following ASP script shows how to access the root element of the XML document: Module7: Posting XMLDatafromClienttoServer 27 Updating the Database Slide Objective To introduce the concept of database access and update Lead-in The clientdata is now contained in an XMLDOM object... generated XML document containing a mixture of boilerplate XML definitions, datafromXMLdata islands, and data created from user input at the client Example of building an XMLdata packet For example, if you send data about a customer’s order from the clientto the server, you need to wrap the order XMLdata with the customer’s ID The following script creates an XMLDOM object and loads a boilerplate XML . techniques specific to posting XML data from the client to the server. Module 7: Posting XML Data from Client to Server 3 Client/ Server XML Application Architecture. being sent to the data source. 4 Module 7: Posting XML Data from Client to Server Sending XML Data from Client to Server ! Client creates an XML data packet