Tài liệu Module 3: Validating XML - Pdf 84



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

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.

!
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

!
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
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.


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
!

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

!
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
Module 3: Validating XML 7 Sometimes the DTD is supplied within the XML document that it validates.
The DTD is referenced just after the XML declaration, as follows:
<?xml version='1.0'?>
<!DOCTYPE bookstore [


The DTD, as an XML validation technology, is being replaced by the W3C
XSD Recommendation. Projects that are currently deployed that use DTDs may
need to be updated. There are many DTD-to-schema conversion utilities
available.
How to recognize a
reference to an inline
DTD
DTD-to-schema
conversion
8 Module 3: Validating XML How to Recognize an XDR Schema
!
External XDR schema
!
Inline XDR schema
!
Reference to an XDR schema in a source document
<Schema name="MySchema" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<Schema name="MySchema" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<root xmlns:data="x-schema:#inLineSchema">
<Schema name ="inLineSchema“ xmlns="urn:schemas-microsoft-com:xml-data">
<ElementType name="myelement"/>
</Schema>
<data:myelement>inline example</data:myelement>
</root>

<?xml version="1.0"?>
<Schema name="schema_sample_1"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="PERSONA" content="textOnly"
model="closed"/>
<ElementType name="GRPDESCR" content="textOnly"
model="closed"/>
<ElementType name="PGROUP" content="eltOnly" model="closed">
<element type="PERSONA" minOccurs="1" maxOccurs="*"/>
<element type="GRPDESCR" minOccurs="1" maxOccurs="1"/>
</ElementType>
</Schema>

Introduction
How to recognize an
XDR schema
Example


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status