xsd presented by kushan athukorala. 2 agenda xml namespaces xml schema xsd indicators xsd data types...

21
XSD Presented by Kushan Athukorala

Upload: marshall-copeland

Post on 20-Jan-2016

257 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

XSDPresented by Kushan Athukorala

Page 2: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

2

Agenda

• XML Namespaces• XML Schema• XSD Indicators• XSD Data Types• XSD Schema References

Page 3: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

3

XML Namespaces

• XML Namespaces provide a method to avoid element name conflicts• This XML carries HTML table information:

<table>  <tr>    <td>Apples</td>    <td>Bananas</td>  </tr></table>

• This XML carries information about a table (a piece of furniture):

<table>  <name>African Coffee Table</name>  <width>80</width>  <length>120</length></table>

• If these XML fragments were added together, there would be a name conflict

Page 4: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

4

Solving the Name Conflict Using a Prefix

<h:table>  <h:tr>    <h:td>Apples</h:td>    <h:td>Bananas</h:td>  </h:tr></h:table>

<f:table>  <f:name>African Coffee Table</f:name>  <f:width>80</f:width>  <f:length>120</f:length></f:table>

Page 5: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

5

Defining xmlns Attribute

• Two ways• Defining in each child element <root>

<h:table xmlns:h="http://www.w3.org/TR/html4/">  <h:tr>    <h:td>Apples</h:td>    <h:td>Bananas</h:td>  </h:tr></h:table><f:table xmlns:f="http://www.w3schools.com/furniture">  <f:name>African Coffee Table</f:name>  <f:width>80</f:width>  <f:length>120</f:length></f:table></root>

• Defining in the root element <root

xmlns:h="http://www.w3.org/TR/html4/"xmlns:f="http://www.w3schools.com/furniture"><h:table>  <h:tr>    <h:td>Apples</h:td>    <h:td>Bananas</h:td>  </h:tr></h:table><f:table>  <f:name>African Coffee Table</f:name>  <f:width>80</f:width>  <f:length>120</f:length></f:table></root>

Page 6: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

6

XML Schema

• An XML Schema describes the structure of an XML document

• XML based alternative to DTD <?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">  <xs:complexType>    <xs:sequence>      <xs:element name="to" type="xs:string"/>      <xs:element name="from" type="xs:string"/>      <xs:element name="heading" type="xs:string"/>      <xs:element name="body" type="xs:string"/>    </xs:sequence>  </xs:complexType></xs:element>

</xs:schema>

• The XML Schema language is also referred to as XML Schema Definition (XSD)

Page 7: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

7

XML Schema contd.

• The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.

• An XML Schema:• defines elements that can appear in a document• defines attributes that can appear in a document• defines which elements are child elements• defines the order of child elements• defines the number of child elements• defines whether an element is empty or can include text• defines data types for elements and attributes• defines default and fixed values for elements and attributes

Page 8: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

8

Simple Types

• Simple Elements• A simple element is an XML element that contains only text• It cannot contain any other elements or attributes

• Defining a Simple Element• <xs:element name="xxx" type="yyy"/>

where xxx is the name of the element and yyy is the data type of the element

• Default and Fixed Values for Simple Elements• <xs:element name="color" type="xs:string" default="red"/>• <xs:element name="color" type="xs:string" fixed="red"/>

• All attributes are declared as simple types• <xs:attribute name="xxx" type="yyy"/>

Page 9: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

9

Complex Types

• A complex element contains other elements and/or attributes.

• There are four kinds of complex elements:• empty elements • elements that contain only other elements • elements that contain only text • elements that contain both other elements and text

• Lets look at some examples

Page 10: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

10

Complex Element which is Empty

• A complex XML element, "product", which is empty• <product pid="1345"/>

Page 11: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

11

Complex Element which contains only other elements

• A complex XML element, "employee", which contains only other elements• <employee>

  <firstname>John</firstname>  <lastname>Smith</lastname></employee>

Page 12: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

12

Complex Element which contains only text

• A complex XML element, "food", which contains only text• <food type="dessert">Ice cream</food>

Page 13: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

13

Complex Element which contains both elements and text

• A complex XML element, "description", which contains both elements and text• <description>

It happened on <date lang="norwegian">03.03.99</date> ....</description>

Page 14: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

14

How to Define a Complex Element in an XML Schema

• There are two ways• 1. <xs:element name="employee">

  <xs:complexType>    <xs:sequence> << Indicators      <xs:element name="firstname" type="xs:string"/>      <xs:element name="lastname" type="xs:string"/>    </xs:sequence>  </xs:complexType></xs:element>

• If you use the method described above, only the "employee" element can use the specified complex type.

Page 15: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

15

• 2. <xs:element name="employee" type="personinfo"/>

<xs:element name="student" type="personinfo"/><xs:element name="member" type="personinfo"/>

<xs:complexType name="personinfo">  <xs:sequence>    <xs:element name="firstname" type="xs:string"/>    <xs:element name="lastname" type="xs:string"/>  </xs:sequence></xs:complexType>

• With this approach, several elements can refer to the same complex type

Page 16: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

16

XSD Indicators

• There are seven indicators:• Order indicators:

• All • Choice • Sequence

• Occurrence indicators:• maxOccurs • minOccurs

• Group indicators:• Group name • attributeGroup name

Page 17: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

17

Assignments

• Assignment1• Build your own xsd examples for each indicator. Make sure

not to take examples from Google• Create a Test Strategy for your examples with boundary

value analysis.

Page 18: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

18

Data Types

• XML Schema has a lot of built-in data types. The most common types are:• xs:string• xs:decimal• xs:integer• xs:boolean• xs:date• xs:time

• Assignment2 – Build your own xsd examples for each Datatype. Make sure not to take examples from Google.

Page 19: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

19

Schema References

• Study the following on the web• XSD Elements

• Assignment3 – Explain the operation of two XSD elements other than simpleType and complexType elements with appropriate examples.

• XSD Restrictions/Facets for Data types

• Assignment4 – Explain the operation of two constraints with examples.

Page 20: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

20

Thank You

Page 21: XSD Presented by Kushan Athukorala. 2 Agenda XML Namespaces XML Schema XSD Indicators XSD Data Types XSD Schema References

21

USA INDIA SRILANKA UK

www.virtusa.com

© V I r t u s a C o r p o r a t i o n

"Virtusa" is a trademark of the company and a registered trademark in the EU and In India. "Productization" is a service mark of the company and a registered service mark in the United States.

"vRule" is a service mark of the company.

For more information please contact [email protected]