XML Schema - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

XML Schema

Description:

A definition language that enables you to constrain conforming XML documents to ... product id='P02' title='RC Racer' price='89.99' category toys /category ... – PowerPoint PPT presentation

Number of Views:339
Avg rating:3.0/5.0
Slides: 15
Provided by: Cla50
Category:
Tags: xml | racer | schema

less

Transcript and Presenter's Notes

Title: XML Schema


1
XML Schema
  • http//www.w3c.org/XML/Schema

2
XML Schema
  • A definition language that enables you to
    constrain conforming XML documents to a specific
    vocabulary and a specific hierarchical structure
  • Element types, attribute types, complex types
  • Two types of documents a schema document and
    multiple instance documents that conform to the
    schema
  • A schema definition is a blueprint (template) of
    a type and each instance is an incarnation of
    that template
  • Two roles that a schema can play
  • Template for a form generator to generate
    instances of a document type
  • Validator to ensure the accuracy of documents

3
Schema and Instances
4
XML Schema (Cont.)
  • Both the schema document and the instance
    document use XML syntax (tags, elements, and
    attributes)
  • Each instance document must declare which schema
    it adhere to
  • Use a special attribute attached to the root
    element called"xsinoNamespaceSchemaLocation"
    or"xsischemaLocation"
  • Depend on whether your vocabulary is defined in
    the context of a namespace
  • XML Schemas allow validation of instances to
    ensure the accuracy of field values and document
    structure at the time of creation
  • Field types, legal element and attribute names,
    correct number of children, and required
    attributes

5
What do Schemas Look Like?
  • An XML Schema uses XML syntax to declare a set of
    simple and complex type declarations
  • A type is named template that can hold one or
    more values
  • Simple types hold one value
  • Complex types are composed of multiple simple
    types
  • A type has two key characteristics a name and a
    legal set of values
  • Simple type an element declaration that includes
    its name and value constraints
  • ltxsdelement name"author" type"xsdstring" /gt
  • ltauthorgt Mike Daconta lt/authorgt

6
Common XML Schema Primitive Data Types
You can define custom data types
7
Define Custom Data Types
ltxsdsimpleType name"skuType"gt
ltxsdrestriction base"xsdstring"gt
ltxsdpattern value"\d 3 -A-Z 2 "/gt
lt/xsdrestrictiongt lt/xsdsimpleTypegt
ltxsdsimpleType name"stateType"gt
ltxsdrestriction base"xsdstring"gt
ltxsdenumeration value"AK"/gt
ltxsdenumeration value"AL"/gt
ltxsdenumeration value"AR"/gt ...
lt/xsdrestrictiongt lt/xsdsimpleTypegt

ltxsdsimpleType name"poIdType"gt
ltxsdrestriction base"xsdinteger"gt
ltxsdminExclusive value"10000"/gt
ltxsdmaxExclusive value"100000"/gt
lt/xsdrestrictiongt lt/xsdsimpleTypegt
8
What do Schemas Look Like? (Cont.)
  • Complex type an element that either contains
    other elements or has attached attributes
  • ltxsdelement name"book" ltxsdcomplexTypegt
    ltxsdattribute name"title" type"xsdstring" /gt
    ltxsdattribute name"pages" type"xsdint" /gt
    lt/xsdcomplexTypegtlt/xsdelementgt
  • ltbook title"More Java Pitfalls" page"453" /gt

9
What do Schemas Look Like? (Cont.)
  • Another example of Complex type
  • ltxsdelement name"product" ltxsdcomplexTypegt
    ltxsdsequencegt ltxsdelement
    name"description" type"xsdstring"
    minOccurs"0" maxOccurs"1" /gt ltxsdelement
    name"category" type"xsdstring"
    minOccurs"1" maxOccurs"unbounded" /gt lt/xsd
    sequencegt ltxsdattribute name"id"
    type"xsdID" /gt ltxsdattribute name"title"
    type"xsdstring" /gt ltxsdattribute
    name"price" type"xsddecimal" /gt
    lt/xsdcomplexTypegtlt/xsdelementgt

10
What do Schemas Look Like? (Cont.)
  • ltproduct id"P01" title"Wonder Teddy"
    price"49.99"gt ltdescriptiongt The best selling
    teddy bear of the year. lt/descriptiongt
    ltcategorygt toys lt/categorygt ltcategorygt stuffed
    animals lt/categorygtlt/productgt
  • ltproduct id"P02" title"RC Racer"
    price"89.99"gt ltcategorygt toys lt/categorygt
    ltcategorygt electronic lt/categorygt ltcategorygt
    radio-controlled lt/categorygt
  • lt/productgt

11
What do Schemas Look Like? (Cont.)
  • Let's Look at a more complex Schema po.xsd

12
Purchase Order Schema
13
Reusability
  • Basic reusability mechanisms address the problems
    of using existing assets in multiple places.
  • Element references
  • Content model groups
  • Attribute groups
  • Schema includes
  • Schema imports
  • Advanced reusability mechanisms address the
    problems of modifying existing assets to serve
    needs that are perhaps different from what they
    were originally designed for
  • Exploit object-oriented idea
  • Extension and Restrictions

14
Is Validation Worth the Trouble?
  • Validation, and the tool support for it, is still
    evolving
  • Until the schema languages mature, validation
    will be a frustrating process that requires
    testing with multiple tools
  • Validation is a critical component of your data
    management process, because
  • XML is intended to be shared and processed by a
    large number and variety of applications
  • A source document may be broken up into XML
    fragments and parts reused ? the cost of errors
    in XML must be multiplied across all the programs
    and partners that rely on that data
  • The chief difficulties with validation data
    types, namespace support, and type inheritance
Write a Comment
User Comments (0)
About PowerShow.com