xml schemas n.
Skip this Video
Download Presentation
XML Schemas

Loading in 2 Seconds...

play fullscreen
1 / 23

XML Schemas - PowerPoint PPT Presentation

  • Uploaded on

XML Schemas. J. Pontes November 15, 2004. Schemas. Defines what a set of one or more document can look like. What elements it contains, order, content, and attributes. These documents are written in XML Schema language. DTD Disadvantages compared to XML. Cannot be parsed by an XML parser

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'XML Schemas' - thuraya-chaka

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
xml schemas

XML Schemas

J. Pontes

November 15, 2004

  • Defines what a set of one or more document can look like.
  • What elements it contains, order, content, and attributes.
  • These documents are written in XML Schema language
dtd disadvantages compared to xml
DTD Disadvantages compared to XML
  • Cannot be parsed by an XML parser
  • All declarations in DTD are global (impossible to define two elements with same name.)
  • DTD cannot control what kind of information a given element or attribute can contain.
what xml schema buys you
What XML Schema Buys You
  • One can define both global elements (used same way all along document) and local elements (particular meaning in a particular context).
  • XML Schemas contain a system of data types.
  • Gives more control over XML document
schema types of content
Schema: types of content
  • Simple Type – text only
  • Complex Types – contain other elements or attributes.
simple type
Simple Type
  • Date
  • Integer
  • String
  • Customer built types
    • In DTD we used #OCDATA to capture a name, a date or practically anything.
complex type
Complex Type
  • Describe the structure of a document, rather than content.
  • Complex Types
    • Elements that contain elements
    • Elements that contain element and text
    • Elements that contain only text
    • Elements that are empty
      • Each may contain attributes
examples of built in simple types
Examples of Built-in Simple Types

<xsd:element name=“weight” type=“xsd:string”/>

<xsd:element name=“population” type=“xsd:integer” />

custom simple type
Custom Simple Type

<xsd:simpleType name=“zipcodeType”>

<xsd:restriction base=“xsd:string”>

<xsd:pattern value=“\d{5}(-\d{4}?” />



This type limits the content of elements (zipcodeType) to a string with 5 digits, an optional hyphen and 4 extra digits.

complex type definition
Complex Type Definition

<xsd:complexType name=“endType”>


<xsd:element name=“animal”

type=“animalType” minOccurs=“1”




Defines endType. It contains another element animal defined with another complex type animalType to define a particular element

local end global declarations
Local end Global declarations
  • Global
    • Declared at top level of a schema, just immediately below xsd:schema element. They are available to be used throughout the the rest of the schema.
    • Global element declaration do not determine where an element can appear in the XML document – they only determine what the element will look like.
    • A global element declaration must be explicitly referenced in order to have it appear in a corresponding XML document.
  • Simple
    • Locally declared elements. Limited to the complex type definition in which they are declared and may not not be used elsewhere in the schema.
    • Such locally declared elements are automatically referenced.
example of local and global elements
Example of Local and Global Elements

<?xml version=“1.0”?>

<xsd:schema smlns:xsd=“http://www.w3.org/2000/10/XMLSchema>

<xsd:element name=“endanged_species” type=“endType”/>

<xsd:element name=“name” type=“xsd:string”/>

<xsd:complexType name=“endType”>


<xsd:element name=“animal”>



<xsd:element ref=“name”


<xsd:element name=“source” type=“sourceType”/>


automatically referenced.

manually referenced.

Same name different definitions.

cont d

<xsd:complexType name=“habitatType”>


<xsd:element name=“river”>



<xsd:element ref=“name”



<xsd:element name=“source” type=“xsd:string”/>


Same name different definitions.

beginning a simple schema
Beginning a Simple Schema

<?xml version=“1.0”?> //Declaring XML

<xsd:schema xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema ”

  • Any element or type that is prefixed with xsd: will be recognized as coming from namespace*
  • Schema rules go in this space.


  • Save you schema as a text only with the .xsd extension.
indicating a location
Indicating a Location

<?xml version=“1.0”?>


xmlns:xsd=“http://www.w3.org/2000/10/XMLSchema-instance ”


“ http://www.cookwook.com/ns/end_species/end_species.xsd ”> *

* file.xsd previously created.

making schemas annotations
Making Schemas Annotations

<?xml version=“1.0”?>

<xsd:schema xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema ”



This schema will be used to validate the set of XML documents for the Endangered Species Project.



defining simple types
Defining Simple Types
  • When declaring an element, you choose its name and what kind of content it should contain.
    • xsd:string – string of characters
    • xsd:decimal – decimal number
    • xsd:boolean – true of false
    • xsd:date – CCYY-MM-DD
    • xsd:time -
    • xsd:uriReference - element will contain an URL
    • xsd:language – two letter language listed in ISO639
    • Custom – name of a custom simple type.
    • Code.xsd

<xsd:elementname="weight" type="xsd:string" />

<xsd:elementname="population" type="xsd:integer" />

    • Code.xml

<weight>500 pounds</weight>


When a value is an integer or a string?

more xml data types
More XML Data Types
  • Click Here for More Data Types
date and time data types
Date and Time Data Types
  • Code.xsd

<xsd:element name=“gestation”


(represent a certain amount of time)

  • Code.xml



n - non negative


T begins optional time section

date and type data types
Date and Type Data Types
  • Code.xsd

xsd:element name=“bedtime” type=“xsd.time:/>

  • Code.xml


additional xsd time
Additional xsd:time
  • xsd:time (hh:mm:ss.sss)
  • xsd:timeInstant (CCYY-MM-DDTh:mm:ss.sss)
  • xsd:date CCYY-MM-DD
  • xsd:month (CCYY-MM
  • xsd:year (CCYY)
  • xsd:century (CC)
  • xsd:recurringDate
  • xsd:recurringDay
number type
Number Type
  • xsd:decimal
  • xsd:integer
  • xsd:positiveinteger
  • xsd:negativeinteger
  • xsd:float
  • xsd:double
xml validator
XML Validator
  • STG XML Validation