Tài liệu Module 3: Validating XML ppt

30 481 0
Tài liệu Module 3: Validating XML ppt

Đ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: Introducing Validation 2 Lesson: Using XSD Schemas 11 Quiz 15 Lab 3: Using Office XP to Generate a Schema 16 Module 3: Validating XML 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 3: Validating XML iii Instructor Notes After completing this module, participants will be able to: ! Identify situations where validation is a requirement. ! Distinguish validation documents that conform to interim schema standards from those that conform to the current schema standard. ! Use Microsoft ® Office XP to create a schema. ! Use a schema to validate an instance document. Required Materials and Preparation Tasks To teach this module, you need the following Microsoft PowerPoint ® files: ! 2500A_03.ppt ! 2500A_03PopQuiz.ppt To prepare for this module: ! Read all of the materials for this module. ! Complete all practices. ! Complete the demonstrations. ! Complete the lab. ! Be ready to explain several situations that require Extensible Markup Language (XML) validation. ! Be ready to explain the difference between a document type definition (DTD), an XML-Data Reduced (XDR) schema, and an XML Schema Definitions (XSD) schema. ! Be ready to describe the World Wide Web Consortium (W3C) schema data types, and attribute and element declarations. Read the W3C XML Schema Definition Primer document and the Microsoft MSDN ® Online topic on XSD schemas. Presentation: 45 Minutes Lab: 20 Minutes Required Materials Preparation Tasks Recommended Readin g iv Module 3: Validating XML Module Strategy This module contains two lessons and one lab. ! Introducing Validation In this lesson, participants learn what validation means. This lesson defines validation and describes its range of application. Participants learn how to identify DTDs and XDR schemas. One of the objectives of this lesson is for participants to be able to recognize DTDs and XDR schemas, and to a lesser extent read them. Participants do not need to know how to generate a DTD or an XDR schema, only to recognize one and to a limited extent, to read one. Emphasize that DTD and XDR are earlier technologies. Spend more time on the second lesson on XSD. ! Using XSD Schemas In this lesson, participants learn the parts of an XSD schema and how to generate one from a Microsoft Access 2002 table. The concept of data types is restricted to discussing two main categories of data types, simple and complex types. The syntax of declaring attribute and element names is discussed. At the close of this lesson is a quiz that presents participants with some example code. To present this quiz, open 2500A_03PopQuiz.ppt. The question and code sample appear first. When you are ready, click the slide and the answer appears. In the quiz, participants identify validation requirements and the type of schema that is being presented. Module 3: Validating XML 1 Overview ! Introducing Validation ! Using XSD Schemas ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** What happens when an application receives a command to process an Extensible Markup Language (XML) document that, although well-formed, is composed according to a vocabulary different from the one that the application is programmed to process? One might expect a variety of errors to occur. The purpose of validating XML is to prevent processing errors at the level of the application. After completing this module, you will be able to: ! Identify situations where validation is a requirement. ! Distinguish validation documents that conform to interim schema standards from those that conform to the current schema standard. ! Use Microsoft ® Office XP to create a schema. ! Use a schema to validate an instance document. Introduction Objectives 2 Module 3: Validating XML Lesson: Introducing Validation ! What Is Valid XML? ! Validation Scenarios ! Evolution of Validation Technologies ! How to Recognize a Document Type Definition ! How to Recognize an XDR Schema ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Validation is fundamental to everything else you do with XML. The standards for validating have changed dramatically over the last three years. After completing this lesson, you will be able to: ! Define XML validation. ! Identify the places in a distributed computing scenario where XML validation is a requirement. ! Describe the evolution of XML validation. ! Identify a document type definition (DTD). ! Differentiate between an XML-Data Reduced (XDR) schema and an XML Schema Definitions (XSD) schema. Introduction Lesson ob jectives Module 3: Validating XML 3 What Is Valid XML? <orders>my data</orders> <orders>my data</orders> Valid XML Not Valid XML <Orders>my data</Orders> <Orders>my data</Orders> Validation XML Processor Application Error! Root element must be lower case. Error! Root element must be lower case. Both documents are well-formed but… A schema is a specification for XML structure and data types A schema is a specification for XML structure and data types Only the valid document reaches the application for further processing ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** For an XML document to be exchanged between applications, it must be well-formed and valid. XML is valid if its vocabulary conforms to a set of requirements, or schema. In computing, a schema is a general term for a description of a set of data. In XML, a schema is a description of an XML document. You use a schema to validate XML documents. An XML document that you validate with a schema is called an instance document. If an instance document matches the schema definition, the instance document is said to be valid. There are three types of schemas for validating an XML instance document. Type of schema Description DTD DTD is the original validation method described in W3C XML Recommendation version 1.0. XSD superceded the DTD. DTDs are not based on XML. XDR schema XDR is an interim schema technology developed by Microsoft. XDR is similar to XSD. XDR schemas are written in XML. XSD schema XSD is the W3C Recommendation for validating XML schemas. It replaces both DTDs and XDR schemas. XSD schemas are written in XML. Introduction Definition Validation terminology and methods 4 Module 3: Validating XML Validation Scenarios ! Data transferred between systems requires validation Organization A Organization A Client Client 1. Validate user input prior to uploading. 2. Validate incoming XML against a required vocabulary. 3. Validate details against business logic prior to processing. Organization B Organization B 1 1 1 2 2 2 3 3 3 2 2 2 ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Validation is a requirement for transferring data between systems that span from one system to another or from one organization to another. Supply chain management is an example where validation is necessary. A supply chain can consist of many business partners, each passing data from one to the next. Each business partner may pass data between its organizational units. Validation ensures that data passed from one point to the next, within and between organizations, is useful. There are three places in a data exchange process where you typically find validation. Point in the process What to validate Client A client can validate the format and completeness of data before sending it to a Web server. Between partners A business partner can validate incoming data against a schema before processing it further. Within an application An application can validate content against business logic before processing it further. There are costs to validating. ! Validation can slow application performance. ! Time is required to develop and manage schemas. ! If you validate data, then you must also develop error handling in case of invalid data. Not all situations require validation. If the XML vocabulary, data types, and data formats contained in the XML you plan to process reliably conform to the requirements of your system, then you might not need to validate the XML. For example, an internal application that consumes its data from sources you control might not require validation. Introduction When to validate When not to validate Module 3: Validating XML 5 How to Recognize a Document Type Definition ! DTDs are superceded by XSD schemas, but you might still need to work around them ! A reference to an external DTD ! An external DTD ! An inline DTD <!ELEMENT bookstore (book)*> <!ELEMENT book (title,author*,price)> <!ATTLIST book genre CDATA #REQUIRED> <!ELEMENT title (#PCDATA)> <!ELEMENT author (name | (first-name,last-name))> <!ELEMENT price (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT first-name (#PCDATA)> <!ELEMENT last-name (#PCDATA)> <!ELEMENT bookstore (book)*> <!ELEMENT book (title,author*,price)> <!ATTLIST book genre CDATA #REQUIRED> <!ELEMENT title (#PCDATA)> <!ELEMENT author (name | (first-name,last-name))> <!ELEMENT price (#PCDATA)> <!ELEMENT name (#PCDATA)> <!ELEMENT first-name (#PCDATA)> <!ELEMENT last-name (#PCDATA)> <?xml version='1.0'?><!DOCTYPE bookstore SYSTEM "books.dtd"> <?xml version='1.0'?><!DOCTYPE bookstore SYSTEM "books.dtd"> <?xml version='1.0'?> <!DOCTYPE bookstore [ <!ELEMENT bookstore (book)*> <?xml version='1.0'?> <!DOCTYPE bookstore [ <!ELEMENT bookstore (book)*> DTD Example ***************************** ILLEGAL FOR NON - TRAINER USE ****************************** Although DTDs have been superceded by XSD schemas, you may still encounter a DTD in earlier code. Therefore, you should be able to read and understand a DTD. DTD validation is defined in the World Wide Web Consortium (W3C) XML 1.0 Recommendation. A DTD is a schema based on Standard Generalized Markup Language (SGML). You use DTDs to specify the content and values that are allowed for an XML document. DTDs use a formal vocabulary to describe the structure and syntax of XML documents. The DTD may be located in a file external to the XML document, or it may be inline, located within the XML document. The <!DOCTYPE> declaration is required to reference a DTD. You can determine if an XML document is validated against a DTD if a DTD is referenced within a <!DOCTYPE> declaration. The name of the root element of the XML file is also specified in the <!DOCTYPE> declaration. A system keyword or public keyword follows. If the SYSTEM keyword is used, the location value must be set to a valid Uniform Resource Locator (URL). If the PUBLIC keyword is used, the location value is simply passed to whatever application is using the DTD for the application to resolve. The following is the syntax for the <!DOCTYPE> declaration: <!DOCTYPE RootElementName [SYSTEM|PUBLIC] "Location"> Introduction Definition How to recognize a reference to an external DTD Syntax 6 Module 3: Validating XML In the following example, an instance document is validated against an external DTD: <?xml version="1.0"?> <!DOCTYPE StockList SYSTEM "List.dtd"> <StockList> <Item Quant=’1000’ SKU=’13’>Thermometer</Item> <Item Quant=’10’ SKU=’45’>Flashlight</Item> <Item Quant=’4’ SKU=’23’>Timer</Item> <Item Quant=’1’ SKU=’98’>Plastic Tray</Item> </StockList> Notice the following: ! <StockList> and all child elements are validated against the DTD that the SYSTEM keyword references. ! The SYSTEM keyword indicates that List.dtd is a literal URL reference. Here is an example of an external DTD with the file name List.dtd: <!ELEMENT StockList (Item)*> <!ATTLIST Item Quant CDATA #REQUIRED> <!ATTLIST Name SKU CDATA #REQUIRED> Notice the following: ! It is not an XML document in form or name. ! It specifies that the root element must be named <StockList>. ! Any number of child elements called <Item> may be present. ! Each <Item> element requires value declarations for the attributes Quant and SKU. Example of a reference to an external DTD Example of an external DTD [...]... 8 Module 3: Validating XML How to Recognize an XDR Schema ! External XDR schema xmlns:dt="urn:schemas-microsoft-com:datatypes"> ! Inline XDR schema ... Module 3: Validating XML How to recognize an inline XDR schema In Microsoft XML Parser (MSXML) version 2 and later, a schema may be included inline within the document that references it, as in the following example The number sign (#) before the schema name indicates that the schema is inline ... DTD with the functionality of an XSD schema ! Use Microsoft Access 2002 to generate an XSD schema 12 Module 3: Validating XML Parts of an XSD Schema ! XSDs reference the W3C XML Schema namespace " XSD names are prefixed with xsd: ! Element and attribute declarations ! Data types definitions... install_folder\Democode\Mod03\PeriodicTable .xml 4 On the XML menu, click Create Schema 5 Save PeriodicTable.xsd to the install_folder\Democode\Mod03 folder ! Edit the schema 1 In the schema editor, change BoilingPointF to an attribute To do this, click E next to BoilingPointF, and then click attribute 2 To see how the XML was changed, click XML at the bottom of the window Module 3: Validating XML 15 Quiz ! Time for a... change the name of the file tblCat .xml to tblCatDTD .xml ! Validate with an XSD schema 1 Rename the CopytblCat .xml file tblCat .xml 2 In Notepad, open tblCat .xml and create a statement to assign the XSD file to the tblCat .xml file 3 Open tblCat .xml in Internet Explorer to verify that it displays properly 4 Open the validate.htm file again and validate your new copy of tblCat .xml Is your file valid? 5 Now,... How to recognize an XDR schema An XML file is an XDR schema when: ! ! The root element is named or ! Example The file extension is xdr or xml There are references to Microsoft schema namespaces The following is an example of an XDR schema named Play .xml: < ?xml version="1.0"?> ... further broken down by the XML processor In XSD, the complex data type was designed to define attribute-to-element relationships and nesting relationships between elements These relationships are sometimes referred to as the data model of an XML document Note For more information about XSD schema data types, see XML Data Types Reference at MSDN Online 14 Module 3: Validating XML Demonstration: Generating.. .Module 3: Validating XML 7 How to recognize a reference to an inline DTD Sometimes the DTD is supplied within the XML document that it validates The DTD is referenced just after the XML declaration, as follows: DTD-to-schema conversion The DTD, as an XML validation technology, is being replaced by the W3C XSD Recommendation... file named 2500_03PopQuiz .ppt and ask you to answer questions on the slides 16 Module 3: Validating XML Lab 3: Using Office XP to Generate a Schema ! Exercise 1: Using Access 2002 Help to Find Information on Using Schemas ! Exercise 2: Using XSD to Validate Data ! Exercise 3 (Optional): Comparing Validation Methods ! If Time Permits: Reviewing Additional Scenarios That Use XML with Access *****************************ILLEGAL... (#PCDATA)> 22 Module 3: Validating XML The XSD file named tblCat.xsd looks like this: < ?xml version="1.0"?> . Materials Preparation Tasks Recommended Readin g iv Module 3: Validating XML Module Strategy This module contains two lessons and one lab. ! Introducing. (XDR) schema and an XML Schema Definitions (XSD) schema. Introduction Lesson ob jectives Module 3: Validating XML 3 What Is Valid XML? <orders>my

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

Từ khóa liên quan

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

Tài liệu liên quan