• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
3   xml namespaces and xml schema
 

3 xml namespaces and xml schema

on

  • 818 views

Namespace, schema - XML

Namespace, schema - XML

Statistics

Views

Total Views
818
Views on SlideShare
818
Embed Views
0

Actions

Likes
0
Downloads
31
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    3   xml namespaces and xml schema 3 xml namespaces and xml schema Presentation Transcript

    • XML Namespaces and XML Schema Atul Kahate [email_address]
    • XML Namespaces
    • Need for Namespaces
      • XML allows document authors to create custom elements
      • At times, this leads to ambiguity/collisions
      • Example:
        • <subject>Geometry</subject>
        • <subject>Cardiology</subject>
      • The first subject is the one we study in college, the other one in medicine – but there is nothing to differentiate between them
    • Using Namespaces
      • We can resolve this problem by using namespaces as follows:
        • <highschool:subject>Geometry</highschool:subject>
        • <medicine:subject>Cardiology</medicine:subject>
      • Both highschool and medicine are namespace prefixes
      • We can provide any namespace prefix we want, except for the reserve words
    • Namespace Example
      • <?xml version = &quot;1.0&quot;?>
      • <text:directory
      • xmlns:text = &quot;www.one.com&quot;
      • xmlns:image = &quot;www.two.com&quot;>
      • <text:file filename = &quot;book.xml&quot;>
      • <text:description>A book list</text:description>
      • </text:file>
      • <image:file filename = &quot;book.xml&quot;>
      • <image:description>A funny picture</image:description>
      • <image:size width = &quot;200&quot; height = 100&quot; />
      • </image:file>
      • </text:directory>
    • Using Default Namespace
      • <?xml version = &quot;1.0&quot;?>
      • <directory
      • xmlns = &quot;www.one.com&quot;
      • xmlns:image = &quot;www.two.com&quot;>
      • <file filename = &quot;book.xml&quot;>
      • <description>A book list</description>
      • </file>
      • <image:file filename = &quot;book.xml&quot;>
      • <image:description>A funny picture</image:description>
      • <image:size width = &quot;200&quot; height = 100&quot; />
      • </image:file>
      • </directory>
      • Now, directory is an element that has a default namespace (i.e. no prefix attached).
    • Well-formed and Valid XML
    • Well-formed and Valid Documents
      • Well-formed documents
        • Adhere to all the basic rules of XML document design
      • Valid documents
        • A well-formed document that also adheres to its DTD rules
      • All well-formed documents need not be valid documents
    • XML Schemas
    • XML Schemas
      • Similar in concept to a DTD
      • Describes the data elements, attributes and their inter-relationships in an XML document
      • Schema syntax is much closer to the XML tag syntax
    • DTD Versus Schema: An Example
    • XML Example – Using DTD
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!DOCTYPE BOOK SYSTEM &quot;book_first.dtd&quot;>
      • < BOOK >
      • < BOOK_NAME > Computer Networks </ BOOK_NAME >
      • < AUTHOR > Andrew Tanenbaum </ AUTHOR >
      • < PUBLISHER > Pearson Education </ PUBLISHER >
      • < CATEGORY > Internet Technologies </ CATEGORY >
      • </ BOOK >
    • DTD Example
      • <!ELEMENT BOOK (BOOK_NAME, AUTHOR, PUBLISHER, CATEGORY)>
      • <!ELEMENT BOOK_NAME (#PCDATA)>
      • <!ELEMENT AUTHOR (#PCDATA)>
      • <!ELEMENT PUBLISHER (#PCDATA)>
      • <!ELEMENT CATEGORY (#PCDATA)>
    • XML Document – Using Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • < BOOK xmlns:xsi =&quot; http://www.w3.org/2001/XMLSchema-instance &quot;
      • xsi:noNamespaceSchemaLocation =&quot; book_first.xsd &quot;>
      • < BOOK_NAME > Computer Networks </ BOOK_NAME >
      • < AUTHOR > Andrew Tanenbaum </ AUTHOR >
      • < PUBLISHER > Pearson Education </ PUBLISHER >
      • < CATEGORY > Internet Technologies </ CATEGORY >
      • </ BOOK >
    • Corresponding Schema
      • Let us write this as a schema now …
      • <?xml version=&quot;1.0&quot;?>
      • <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <xsd:element name=&quot;BOOK&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;BOOK_NAME&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;AUTHOR&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;PUBLISHER&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;CATEGORY&quot; type=&quot;xsd:string&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
    • Exercise – 1
      • We want to keep information about an employee in the form of employee ID, name, department, salary, and date of joining. Create an XML document and write corresponding DTD and schema.
    • Exercise – 2
      • Modify the above example to split the name into first and last name
    • Schema Basics and Syntaxes
    • The <schema> Element
      • Root element of every XML schema
        • <?xml version=&quot;1.0&quot;?>
        • <xsd: schema >
        • ...
        • ...
        • </xsd: schema >
      • Usually contains attributes, as shown next
    • Attributes in the <schema> Element
      • <?xml version=&quot;1.0&quot;?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
      • targetNamespace=&quot;http://www.test.com&quot;
      • xmlns=&quot;http://www.xyz.com&quot;
      • elementFormDefault=&quot;qualified&quot;>
      • ...
      • ...
      • </xsd:schema>
      • xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; indicates that the data types and elements used inside this schema come from this namespace and they should be prefixed with xsd:
      • targetNamespace=&quot;http://www.test.com&quot; indicates that the user-defined XML elements, attributes etc come from this schema
      • xmlns=&quot;http://www.xyz.com“ is the default namespace
      • elementFormDefault=&quot;qualified&quot; mandates usage of namespaces for all elements in the current XML document
    • Referencing a Schema from an XML File
      • <?xml version=&quot;1.0&quot;?>
      • <note xmlns=&quot;http://www.xyz.com&quot;
      • xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      • xsi:schemaLocation=&quot;http://www.xyz.com note.xsd&quot;>
      • <to>Ram</to>
      • <from>Krishna</from>
      • <heading>Reminder</heading>
      • <body>Please send me your XML notes!</body>
      • </note>
      Default namespace Namespace and schema file name
    • Defining Simple Elements
      • A simple element is an XML element that can contain only text (strings, dates, Boolean values, etc). It cannot contain any other elements or attributes.
      • Syntax
        • <xsd:element name=&quot;xxx&quot; type=&quot;yyy&quot;/>
      • Examples
        • <lastname>Tanenbaum</lastname>
        • <age>60</age>
        • <dateborn>1945-10-08</dateborn>
      • Corresponding schema declarations
        • <xsd:element name=&quot;lastname&quot; type=&quot;xsd:string&quot;/>
        • <xsd:element name=&quot;age&quot; type=&quot;xsd:integer&quot;/>
        • <xsd:element name=&quot;dateborn&quot; type=&quot;xsd:date&quot;/>
    • Schema Data Types and Default or Constant Values
      • Basic data types
        • xsd:string
        • xsd:decimal
        • xsd:integer
        • xsd:boolean
        • xsd:date
        • xsd:time
      • Declaring default values
        • <xsd:element name=&quot;color&quot; type=&quot;xsd:string&quot; default=&quot;red&quot;/>
      • Declaring constant values
        • <xsd:element name=&quot;color&quot; type=&quot;xsd:string&quot; fixed=&quot;red&quot;/>
    • Declaring Attributes in Schemas
      • Simple elements cannot have attributes.
      • If an element has attributes, it is considered to be of complex type.
      • But the attribute itself is always declared as a simple type.
      • This means that an element with attributes always has a complex type definition.
      • Syntax
        • <xsd:attribute name=&quot;xxx&quot; type=&quot;yyy&quot;/>
      • Example
        • <lastname lang=&quot;EN&quot;>Joshi</lastname>
      • Corresponding schema declaration
        • <xsd:attribute name=&quot;lang&quot; type=&quot;xsd:string&quot;/>
    • More on Attributes
      • Default values
        • <xsd:attribute name=&quot;lang&quot; type=&quot;xsd:string&quot; default=&quot;EN&quot;/>
      • Fixed values
        • <xsd:attribute name=&quot;lang&quot; type=&quot;xsd:string&quot; fixed=&quot;EN&quot;/>
      • Mandatory attributes
        • <xsd:attribute name=&quot;lang&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;/>
      • Optional attributes
        • <xsd:attribute name=&quot;lang&quot; type=&quot;xsd:string&quot; use=&quot;optional&quot;/>
    • Schema Example – See the difference between “ref” and “type”
    • XML
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
      • <Employee lastUpdated=&quot;2007-04-21&quot;
      • xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      • xsi:noNamespaceSchemaLocation=&quot;emp_first.xsd&quot;>
      • <!-- <Employee lastUpdated=&quot;2007-04-21&quot;> -->
      • <Name>Manish Potdar</Name>
      • <Contact>
      • <EmpAddress>
      • <Street>12 East Street</Street>
      • <City>Pune</City>
      • <Pin>411001</Pin>
      • <State>Maharashtra</State>
      • </EmpAddress>
      • <HomePhone>02025530834</HomePhone>
      • <Email>manish@yahoo.com</Email>
      • </Contact>
      • </Employee>
    • Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; elementFormDefault=&quot;qualified&quot; attributeFormDefault=&quot;unqualified&quot;>
      • <xsd:element name=&quot;Employee&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;Name&quot;/>
      • <xsd:element name=&quot;Contact&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name = &quot;EmpAddress&quot; type=&quot;Address&quot;/>
      • <xsd:element name=&quot;HomePhone&quot;/>
      • <xsd:element name=&quot;Email&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:sequence>
      • <xsd:attribute name=&quot;lastUpdated&quot;/>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:complexType name=&quot;Address&quot;>
      • <xsd:sequence>
      • <xsd:element name=&quot;Street&quot;/>
      • <xsd:element name=&quot;City&quot;/>
      • <xsd:element name=&quot;Pin&quot;/>
      • <xsd:element name=&quot;State&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:schema>
    • Modified XML (emp_first.xml)
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?>
      • <Employee lastUpdated=&quot;2007-04-21&quot;
      • xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      • xsi:noNamespaceSchemaLocation=&quot;emp_first.xsd&quot;>
      • <Name>Manish Potdar</Name>
      • <Contact>
      • <Address>
      • <Street>12 East Street</Street>
      • <City>Pune</City>
      • <Pin>411001</Pin>
      • <State>Maharashtra</State>
      • </Address>
      • <HomePhone>02025530834</HomePhone>
      • <Email>manish@yahoo.com</Email>
      • </Contact>
      • </Employee>
    • Modified Schema (emp_first.xsd)
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <xsd:element name=&quot;Employee&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;Name&quot;/>
      • <xsd:element name=&quot;Contact&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;Address&quot;/>
      • <xsd:element name=&quot;HomePhone&quot;/>
      • <xsd:element name=&quot;Email&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:sequence>
      • <xsd:attribute name=&quot;lastUpdated&quot;/>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;Address&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;Street&quot;/>
      • <xsd:element name=&quot;City&quot;/>
      • <xsd:element name=&quot;Pin&quot;/>
      • <xsd:element name=&quot;State&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
    • Exercise
      • Maintain employee information in the form of employee ID, name, department, salary, and date of joining. Keep maximum information in the form of attributes, rather than as elements. Create an XML document and write and schema.
    • Schema and Data Types
      • Schemas provide a much wider range of data types than DTDs
        • Boolean, Date-related, String, Numeric
      • Add flexibility to element declarations
        • Examples
          • <simpleType name=“humanAges”>
          • <minInclusive base=“double” value=“0.0” />
          • <maxInclusive base=“double” value=“150.0” />
          • </simpleType>
          • <simpleType name=“comment”>
          • <maxLength base=“string” value=“1024” />
          • </simpleType>
    • Schema and DTD
      • DTD can be converted into schema
      • Equivalences need to be found
      • Example, consider an element test
      Unbounded 1 1 or more occurrences test+ Unbounded 0 0 or more occurrences test* 1 1 Exactly 1 occurrence test 1 0 0 or 1 occurrences test? maxOccurs in schema minOccurs in schema Meaning DTD Syntax
    • Schema Components
    • Schema Components
      • Generic term for the blocks that make up the abstract data model of the schema syntax
      • There are 12 components, split into three groups
        • Primary components – Simple and complex type definitions, Element and attribute declarations
        • Secondary components – Attribute groups, Identity constraints, Model group definitions
        • Helper components – Not named or accessed independently
    • Primary Components
    • Primary Components
      • Element declarations
      • Simple type definitions – Can hold only values, not child elements, or attributes
      • Complex type definitions – Can have sub-elements and attributes
      • Attribute declarations
      • Note: We declare attributes and elements , but define types
    • Declaring Elements
      • Example
      • <xsd:element name = “dateReceived”/>
      • Or, with data type
      • <xsd:element name = “dateReceived” type = “xsd:date”/>
    • Specifying Element Occurrences
      • minOccurs and maxOccurs can be used
      • Examples
      • <xsd:element name = “dateReceived” type = “xsd:date” minOccurs = “0” maxOccurs = “1”/>
      • <xsd:element name = “student” type = “xsd:string” minOccurs = “1” maxOccurs = “unbounded”/>
    • Simple and Complex Types
      • Simple types
        • Allow atoms of data (element or attribute values) that cannot be divided further
        • Hence, only elements that do not have child elements or attributes are of simple type
      • Complex types
        • Can contain other elements and attributes
    • Simple Types
      • Contain information that cannot be split further
      • Example
      • XML
      • <myElement>I am simple</myElement>
      • Schema
      • < xsd:element name =&quot; myElement &quot; type =&quot; xsd:string &quot;/>
    • Simple Data Types – Classification
      • Two types
        • Built-in types
          • Primitive types – Examples are string, boolean, number, float, double, decimal, dateTime, time, date, etc
          • Derived types – Examples are integer, nonPositiveInteger, negativeInteger, long, int, short, byte, nonNegativeInteger, unsignedInt, positiveInteger, etc
        • User-derived types
    • Named Complex Types
      • Allow elements to contain sub-elements and attributes; thus, allow creation of content models
      • Schema
        • <xsd:complexType name= &quot;Address&quot;>
        • <xsd:sequence>
        • <xsd:element name = &quot;Street1&quot; />
        • <xsd:element name = &quot;Street2&quot; />
        • <xsd:element name = &quot;City&quot; />
        • <xsd:element name = &quot;Pin&quot; />
        • <xsd:element name = “ State &quot; />
        • </xsd:sequence>
        • </xsd:sequence>
      • XML
        • <xsd:element name = “billingAddress” type = “Address” />
    • Anonymous Complex Types
      • <xsd:element name = &quot;Name&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name = &quot;FirstName&quot; />
      • <xsd:element name = &quot;MiddleInitial&quot; minOccurs = &quot;0&quot; maxOccurs = &quot;unbounded&quot; />
      • <xsd:element name = &quot;LastName&quot; />
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:name>
    • Combining Named and Unnamed Declarations
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; ContactDetails &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element ref =&quot; Contact &quot; minOccurs =&quot; 1 &quot; maxOccurs =&quot; unbounded &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:element name =&quot; Contact &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; Name &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; FirstName &quot;/>
      • < xsd:element name =&quot; MiddleInitial &quot; minOccurs =&quot; 0 &quot; maxOccurs =&quot; unbounded &quot;/>
      • < xsd:element name =&quot; LastName &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:element name =&quot; billingAddress &quot; type =&quot; Address &quot;/>
      • < xsd:element name =&quot; mailingAddress &quot; type =&quot; Address &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:complexType name =&quot; Address &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; Street1 &quot;/>
      • < xsd:element name =&quot; Street1 &quot;/>
      • < xsd:element name =&quot; City &quot;/>
      • < xsd:element name =&quot; Pin &quot;/>
      • < xsd:element name =&quot; State &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:schema >
    • Extending Complex Types
      • Suppose we want to add two more properties to the Address complex type in a given situation
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; ContactDetails &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element ref =&quot; Contact &quot; minOccurs =&quot; 1 &quot; maxOccurs =&quot; unbounded &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:element name =&quot; Contact &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; Name &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; FirstName &quot;/>
      • < xsd:element name =&quot; MiddleInitial &quot; minOccurs =&quot; 0 &quot; maxOccurs =&quot; unbounded &quot;/>
      • < xsd:element name =&quot; LastName &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:element name =&quot; billingAddress &quot; type =&quot; Address &quot;/>
      • < xsd:element name =&quot; mailingAddress &quot; type =&quot; Address &quot;/>
      • < xsd:element name =&quot; CreditAddressReference &quot;>
      • < xsd:complexType >
      • < xsd:complexContent >
      • < xsd:extension base =&quot; Address &quot;>
      • < xsd:attribute name =&quot; residentFrom &quot; type =&quot; xsd:date &quot;/>
      • < xsd:attribute name =&quot; residentTo &quot; type =&quot; xsd:date &quot;/>
      • </ xsd:extension >
      • </ xsd:complexContent >
      • </ xsd:complexType >
      • </ xsd:element >
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:complexType name =&quot; Address &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; Street1 &quot;/>
      • < xsd:element name =&quot; Street1 &quot;/>
      • < xsd:element name =&quot; City &quot;/>
      • < xsd:element name =&quot; Pin &quot;/>
      • < xsd:element name =&quot; State &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:schema >
    • Declaring Attributes
      • <xsd:element name = “invoice”>
      • <xsd:complexType>
      • <xsd:attribute name = “paid” use = “optional” default = “true”>
      • </xsd:complexType>
      • </xsd:element>
    • Secondary Components
    • Secondary Components
      • Can be classified into
        • Model group definitions
        • Attribute groups
        • Notation declarations
        • Identity constraints
    • Model group definitions
      • Allows creation of group of element definitions and naming them using a name attribute, so that we can use these groups to build content models
      • We need to use the group element, which must be a top-level schema element, i.e. child of the schema element
      • Once a group is specified, we can also indicate whether only one of them should appear ( choice ) or all of them are needed ( all )
    • group example
      • <?xml version=&quot;1.0&quot;?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <xsd:group name=&quot;custGroup&quot;>
      • <xsd:sequence>
      • <xsd:element name=&quot;customer&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;orderdetails&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;billto&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;shipto&quot; type=&quot;xsd:string&quot;/>
      • </xsd:sequence>
      • </xsd:group>
      • <xsd:element name=&quot;order&quot; type=&quot;ordertype&quot;/>
      • <xsd:complexType name=&quot;ordertype&quot;>
      • <xsd:group ref=&quot;custGroup&quot;/>
      • <xsd:attribute name=&quot;status&quot; type=&quot;xsd:string&quot;/>
      • </xsd:complexType>
      • </xsd:schema>
    • Choice Example – Using group Syntax
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; FlightDetails &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; Name &quot;/>
      • < xsd:group ref =&quot; MealOptions &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:group name =&quot; MealOptions &quot;>
      • < xsd:choice >
      • < xsd:element name =&quot; Vegetarian &quot;/>
      • < xsd:element name =&quot; Non-Vegetarian &quot;/>
      • < xsd:element name =&quot; Salad &quot;/>
      • </ xsd:choice >
      • </ xsd:group >
      • </ xsd:schema >
    • Choice Example – Using Unnamed Syntax
        • <xsd:element name=&quot;person&quot;>
        • <xsd:complexType>
        • <xsd:choice>
        • <xsd:element name=&quot;employee&quot; type=&quot;employee&quot;/>
        • <xsd:element name=&quot;member&quot; type=&quot;member&quot;/>
        • </xsd:choice>
        • </xsd:complexType>
        • </xsd:element>
    • All Example – Using group Syntax
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:group name =&quot; person &quot;>
      • < xsd:all >
      • < xsd:element name =&quot; firstname &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; lastname &quot; type =&quot; xsd:string &quot;/>
      • </ xsd:all >
      • </ xsd:group >
      • < xsd:element name =&quot; test &quot;>
      • < xsd:complexType >
      • < xsd:group ref =&quot; person &quot; />
      • </ xsd:complexType >
      • </ xsd:element >
      • </ xsd:schema >
    • All Example – Using Unnamed Syntax
        • <xsd:element name=&quot;person&quot;>
        • <xsd:complexType>
        • <xsd:all>
        • <xsd:element name=&quot;firstname&quot; type=&quot;xsd:string&quot;/>
        • <xsd:element name=&quot;lastname&quot; type=&quot;xsd:string&quot;/>
        • </xsd:all>
        • </xsd:complexType>
        • </xsd:element>
      • firstname and lastname are mandatory sub-elements – must occur exactly once
    • All – Another Example
      • <xsd:group name = “CreditCardDetails”>
      • <xsd:all>
      • <xsd:element name = “CardType” />
      • <xsd:element name = “CardHolder” />
      • <xsd:element name = “CardNumber” />
      • <xsd:element name = “CardExpiry” />
      • </xsd:all>
      • </xsd:group>
    • Sequence Example using group Syntax
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:group name =&quot; person &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; firstname &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; lastname &quot; type =&quot; xsd:string &quot;/>
      • </ xsd:sequence >
      • </ xsd:group >
      • < xsd:element name =&quot; test &quot;>
      • < xsd:complexType >
      • < xsd:group ref =&quot; person &quot; />
      • </ xsd:complexType >
      • </ xsd:element >
      • </ xsd:schema >
    • Sequence Example Using Unnamed Syntax
      • Another element that we can use inside a group is sequence
      • Example
        • <xsd:group name=&quot;person&quot;>
        • <xsd:complexType>
        • <xsd:sequence>
        • <xsd:element name=&quot;firstname&quot; type=&quot;xsd:string&quot;/>
        • <xsd:element name=&quot;lastname&quot; type=&quot;xsd:string&quot;/>
        • </xsd:sequence>
        • </xsd:complexType>
        • </xsd:element>
    • Other Details
      • We can use minOccurs, maxOccurs attributes on group, choice, sequence, and all elements.
    • Attribute Groups
      • Just as we can group elements together, we can create a group of attributes
      • Attribute groups allow us to define a set of attributes that would be used on a set of elements
      • Attribute groups can nest other attribute groups inside them
    • Attribute Groups - Example
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; product &quot;>
      • < xsd:complexType >
      • < xsd:attributeGroup ref =&quot; productDetails &quot;/>
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:attributeGroup name =&quot; productDetails &quot;>
      • < xsd:attribute name =&quot; productID &quot; use =&quot; required &quot; type =&quot; xsd:string &quot;/>
      • < xsd:attribute name =&quot; productName &quot; use =&quot; required &quot; type =&quot; xsd:string &quot;/>
      • < xsd:attribute name =&quot; productDescription &quot; use =&quot; required &quot; type =&quot; xsd:string &quot;/>
      • < xsd:attribute name =&quot; unit &quot; use =&quot; required &quot; type =&quot; xsd:positiveInteger &quot;/>
      • < xsd:attribute name =&quot; price &quot; use =&quot; required &quot; type =&quot; xsd:decimal &quot;/>
      • < xsd:attribute name =&quot; stock &quot; use =&quot; required &quot; type =&quot; xsd:integer &quot;/>
      • </ xsd:attributeGroup >
      • </ xsd:schema >
    • Default or Fixed Element Content – 1
      • Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; product &quot; default =&quot; book &quot; />
      • </ xsd:schema >
    • Default or Fixed Element Content – 2
      • XML
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • < product lastUpdated =&quot; 2007-04-21 &quot; xmlns:xsi =&quot; http://www.w3.org/2001/XMLSchema-instance &quot; xsi:noNamespaceSchemaLocation =&quot; C:UsersAtulDesktoptest.xsd &quot;>
      • pencil
      • </ product >
      • Or this
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • < product lastUpdated =&quot; 2007-04-21 &quot; xmlns:xsi =&quot; http://www.w3.org/2001/XMLSchema-instance &quot; xsi:noNamespaceSchemaLocation =&quot; C:UsersAtulDesktoptest.xsd &quot;>
      • </ product >
    • Default or Fixed Element Content – 2
      • Usage of Fixed in the Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; product &quot; fixed =&quot; book &quot; />
      • </ xsd:schema >
      • Now, the value of the element in the XML document must either be book , or it should be empty
    • Nillable Elements
      • We can specify that an element must occur or is optional by using the nillable attribute
      • However, we still need to include the nillable element in the XML document, but with a different syntax, as shown in the example
    • Nillable Element Example – 1
      • Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; product &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; productID &quot;/>
      • < xsd:element name =&quot; productName &quot; nillable =&quot; true &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • </ xsd:schema >
    • Nillable Element Example – 2
      • XML
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • < product xmlns:xsi =&quot; http://www.w3.org/2001/XMLSchema-instance &quot; xsi:noNamespaceSchemaLocation =&quot; C:UsersAtulDesktoptest.xsd &quot;>
      • < productID > test </ productID >
      • < productName xsi:nil =&quot; true &quot;/>
      • </ product >
    • Exercise – 1
      • Create an XML document and write the corresponding schema to represent the following information:
        • Trimester number
        • Student’s details
          • Roll number
          • Name
          • Total maximum marks across all subjects
          • Total actual marks across all subjects
          • Percentage of marks
    • Exercise – 2
      • Modify the above example to take care of the following:
        • For every student, maintain a list of any 5 subjects, each with a maximum of 100 marks and actual marks obtained, along with the earlier information
    • Schema Facets
    • Schema Facets (Restrictions) - 1
      • Restriction on values
        • <xsd:element name=&quot;age&quot;>
        • <xsd:simpleType>
        • <xsd:restriction base=&quot;xsd:integer&quot;>
        • <xsd:minInclusive value=&quot;0&quot;/>
        • <xsd:maxInclusive value=&quot;100&quot;/>
        • </xsd:restriction>
        • </xsd:simpleType>
        • </xsd:element>
    • Schema Facets (Restrictions) - 2
      • Restriction on a set of values
      • <xsd:element name=&quot;car“ / >
        • <xsd:simpleType>
        • <xsd:restriction base=&quot;xsd:string&quot;>
        • <xsd:enumeration value=“Santro/>
        • <xsd:enumeration value=“Maruti&quot;/>
        • <xsd:enumeration value=“Indica/>
        • </xsd:restriction>
        • </xsd:simpleType>
      • </xsd:element>
    • Schema Facets (Restrictions) - 3
      • Restrictions on a series of values
        • <xsd:element name=&quot;letter&quot;>
        • <xsd:simpleType>
        • <xsd:restriction base=&quot;xsd:string&quot;>
        • <xsd:pattern value=&quot;[a-z]&quot;/>
        • </xsd:restriction>
        • </xsd:simpleType>
        • </xsd:element>
        • Allows one lowercase alphabet
      • <xsd:pattern value=&quot;[A-Z][A-Z][A-Z]&quot;/>
        • Allows three uppercase alphabets
      • <xsd:pattern value=&quot;[a-zA-Z][a-zA-Z][a-zA-Z]&quot;/>
        • Allows three uppercase or lowercase alphabets
      • <xsd:pattern value=&quot;[xyz]&quot;/>
        • Allows one of the lowercase alphabets x, y, or z
      • <xsd:pattern value=&quot;[0-9][0-9][0-9][0-9][0-9]&quot;/>
        • Allows five digits in sequence
    • Schema Facets (Restrictions) - 4
      • Other restrictions on a series of values
        • <xsd:element name=&quot;letter&quot;>
        • <xsd:simpleType>
        • <xsd:restriction base=&quot;xsd:string&quot;>
        • <xsd:pattern value=&quot;([a-z])*&quot;/>
        • </xsd:restriction>
        • </xsd:simpleType>
        • </xsd:element>
        • Allows 0 or more lowercase alphabets
        • <xsd:pattern value=&quot;([a-z][A-Z])+&quot;/>
          • One or more lowercase alphabets followed by an uppercase alphabet
        • <xsd:pattern value=“worker|manager&quot;/>
          • Allow either worker or manager
        • <xsd:pattern value=&quot;[a-zA-Z0-9]{8}&quot;/>
          • Allow exactly 8 characters, either alphabets or numbers
        • <xsd:length value=&quot;8&quot;/>
          • Allow exactly 8 characters
        • <xsd:minLength value=&quot;5&quot;/>
        • <xsd:maxLength value=&quot;8&quot;/>
          • Allow a minimum of 5 and maximum of 8 characters
    • Schema: Case Study
    • XML Document
      • <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>
      • <shiporder orderid=&quot;889923&quot;
      • xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      • xsi:noNamespaceSchemaLocation=&quot;shiporder.xsd&quot;>
      • <orderperson>John Smith</orderperson>
      • <shipto>
      • <name>Ola Nordmann</name>
      • <address>Langgt 23</address>
      • <city>4000 Stavanger</city>
      • <country>Norway</country>
      • </shipto>
      • <item>
      • <title>Empire Burlesque</title>
      • <note>Special Edition</note>
      • <quantity>1</quantity>
      • <price>10.90</price>
      • </item>
      • <item>
      • <title>Hide your heart</title>
      • <quantity>1</quantity>
      • <price>9.90</price>
      • </item>
      • </shiporder>
      Specifies that this document should be validated against a schema Specifies the location of the schema (in this case, same as that of the XML file)
    • Start with the Schema Template
      • <?xml version=&quot;1.0&quot;?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • ...
      • ...
      • </xsd:schema>
    • Create the shiporder Element Outline
      • <xsd:element name=&quot;shiporder&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • ...
      • ...
      • </xsd:sequence>
      • ...
      • </xsd:complexType>
      • </xsd:element>
    • Define the orderperson Element
      • <xsd:element name=&quot;orderperson&quot; type=&quot;xsd:string&quot;/>
    • Define the shipto and item Elements
      • <xsd:element name=&quot;shipto&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;name&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;address&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;city&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;country&quot; type=&quot;xsd:string&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;item&quot; maxOccurs=&quot;unbounded&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;title&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;note&quot; type=&quot;xsd:string&quot; minOccurs=&quot;0&quot;/>
      • <xsd:element name=&quot;quantity&quot; type=&quot;xsd:positiveInteger&quot;/>
      • <xsd:element name=&quot;price&quot; type=&quot;xsd:decimal&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
    • Declare the attribute for the shiporder Element
      • <xsd:attribute name=&quot;orderid&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;/>
    • The Complete Schema
      • <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <xsd:element name=&quot;shiporder&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;orderperson&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;shipto&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;name&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;address&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;city&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;country&quot; type=&quot;xsd:string&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;item&quot; maxOccurs=&quot;unbounded&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=&quot;title&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;note&quot; type=&quot;xsd:string&quot; minOccurs=&quot;0&quot;/>
      • <xsd:element name=&quot;quantity&quot; type=&quot;xsd:positiveInteger&quot;/>
      • <xsd:element name=&quot;price&quot; type=&quot;xsd:decimal&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:sequence>
      • <xsd:attribute name=&quot;orderid&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;/>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
    • Making it more readable
      • <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <!-- definition of simple elements -->
      • <xsd:element name=&quot;orderperson&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;name&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;address&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;city&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;country&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;title&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;note&quot; type=&quot;xsd:string&quot;/>
      • <xsd:element name=&quot;quantity&quot; type=&quot;xsd:positiveInteger&quot;/>
      • <xsd:element name=&quot;price&quot; type=&quot;xsd:decimal&quot;/>
      • <!-- definition of attributes -->
      • <xsd:attribute name=&quot;orderid&quot; type=&quot;xsd:string&quot;/>
      • <!-- definition of complex elements -->
      • <xsd:element name=&quot;shipto&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;name&quot;/>
      • <xsd:element ref=&quot;address&quot;/>
      • <xsd:element ref=&quot;city&quot;/>
      • <xsd:element ref=&quot;country&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;item&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;title&quot;/>
      • <xsd:element ref=&quot;note&quot; minOccurs=&quot;0&quot;/>
      • <xsd:element ref=&quot;quantity&quot;/>
      • <xsd:element ref=&quot;price&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • <xsd:element name=&quot;shiporder&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element ref=&quot;orderperson&quot;/>
      • <xsd:element ref=&quot;shipto&quot;/>
      • <xsd:element ref=&quot;item&quot; maxOccurs=&quot;unbounded&quot;/>
      • </xsd:sequence>
      • <xsd:attribute ref=&quot;orderid&quot; use=&quot;required&quot;/>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
    • Adding more features
      • <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?>
      • <xsd:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;>
      • <xsd:simpleType name=&quot;stringtype&quot;>
      • <xsd:restriction base=&quot;xsd:string&quot;/>
      • </xsd:simpleType>
      • <xsd:simpleType name=&quot;inttype&quot;>
      • <xsd:restriction base=&quot;xsd:positiveInteger&quot;/>
      • </xsd:simpleType>
      • <xsd:simpleType name=&quot;dectype&quot;>
      • <xsd:restriction base=&quot;xsd:decimal&quot;/>
      • </xsd:simpleType>
      • <xsd:simpleType name=&quot;orderidtype&quot;>
      • <xsd:restriction base=&quot;xsd:string&quot;>
      • <xsd:pattern value=&quot;[0-9]{6}&quot;/>
      • </xsd:restriction>
      • </xsd:simpleType>
      • <xsd:complexType name=&quot;shiptotype&quot;>
      • <xsd:sequence>
      • <xsd:element name=&quot;name&quot; type=&quot;stringtype&quot;/>
      • <xsd:element name=&quot;address&quot; type=&quot;stringtype&quot;/>
      • <xsd:element name=&quot;city&quot; type=&quot;stringtype&quot;/>
      • <xsd:element name=&quot;country&quot; type=&quot;stringtype&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • <xsd:complexType name=&quot;itemtype&quot;>
      • <xsd:sequence>
      • <xsd:element name=&quot;title&quot; type=&quot;stringtype&quot;/>
      • <xsd:element name=&quot;note&quot; type=&quot;stringtype&quot; minOccurs=&quot;0&quot;/>
      • <xsd:element name=&quot;quantity&quot; type=&quot;inttype&quot;/>
      • <xsd:element name=&quot;price&quot; type=&quot;dectype&quot;/>
      • </xsd:sequence>
      • </xsd:complexType>
      • <xsd:complexType name=&quot;shipordertype&quot;>
      • <xsd:sequence>
      • <xsd:element name=&quot;orderperson&quot; type=&quot;stringtype&quot;/>
      • <xsd:element name=&quot;shipto&quot; type=&quot;shiptotype&quot;/>
      • <xsd:element name=&quot;item&quot; maxOccurs=&quot;unbounded&quot; type=&quot;itemtype&quot;/>
      • </xsd:sequence>
      • <xsd:attribute name=&quot;orderid&quot; type=&quot;orderidtype&quot; use=&quot;required&quot;/>
      • </xsd:complexType>
      • <xsd:element name=&quot;shiporder&quot; type=&quot;shipordertype&quot;/>
      • </xsd:schema>
    • Exercise – 1
      • Create schema for the following XML
      • <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
      • < Order xmlns:xsi =&quot; http://www.w3.org/2001/XMLSchema-instance &quot; xsi:noNamespaceSchemaLocation =&quot; C:UsersAtulDesktoptest.xsd &quot;>
      • < Products >
      • < Product >
      • < Product_ID > 100 </ Product_ID >
      • < Product_Name > Book </ Product_Name >
      • < Product_Units > 2 </ Product_Units >
      • < Product_Price > 400 </ Product_Price >
      • </ Product >
      • < Product >
      • < Product_ID > 200 </ Product_ID >
      • < Product_Name > Pen </ Product_Name >
      • < Product_Units > 5 </ Product_Units >
      • < Product_Price > 10 </ Product_Price >
      • </ Product >
      • </ Products >
      • < Contact >
      • < Name > Reshama Joshi </ Name >
      • < Address > 43 Tilak Road </ Address >
      • < City > Pune </ City >
      • < Pin > 411001 </ Pin >
      • </ Contact >
      • < Payment >
      • < CreditCard >
      • < CardType > VISA </ CardType >
      • < CardNumber > 901010111 </ CardNumber >
      • < ExpiryDate > 2012-10-01 </ ExpiryDate >
      • </ CreditCard >
      • < Amount > 1000 </ Amount >
      • </ Payment >
      • </ Order >
    • Solution – 1
      • <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
      • <!-- W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com) -->
      • < xsd:schema xmlns:xs =&quot; http://www.w3.org/2001/XMLSchema &quot;>
      • < xsd:element name =&quot; Order &quot;>
      • < xsd:complexType >
      • < xsd:sequence >
      • < xsd:element name =&quot; Products &quot; type =&quot; productsType &quot;/>
      • < xsd:element name =&quot; Contact &quot; type =&quot; contactType &quot;/>
      • < xsd:element name =&quot; Payment &quot; type =&quot; paymentType &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:element >
      • < xsd:complexType name =&quot; productsType &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; Product &quot; minOccurs =&quot; 1 &quot; maxOccurs =&quot; unbounded &quot; type =&quot; productType &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • < xsd:complexType name =&quot; productType &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; Product_ID &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; Product_Name &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; Product_Units &quot; type =&quot; xsd:positiveInteger &quot;/>
      • < xsd:element name =&quot; Product_Price &quot; type =&quot; xsd:int &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • < xsd:complexType name =&quot; contactType &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; Name &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; Address &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; City &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; Pin &quot; type =&quot; xsd:int &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • < xsd:complexType name =&quot; paymentType &quot;>
      • < xsd:sequence >
      • < xsd:choice >
      • < xsd:element name =&quot; CreditCard &quot; type =&quot; creditCardType &quot;/>
      • < xsd:element name =&quot; Cheque &quot; type =&quot; chequeType &quot;/>
      • </ xsd:choice >
      • < xsd:element name =&quot; Amount &quot; type =&quot; xsd:positiveInteger &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • < xsd:complexType name =&quot; creditCardType &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; CardType &quot; type =&quot; cardTypeRestriction &quot;/>
      • < xsd:element name =&quot; CardNumber &quot; type =&quot; xsd:int &quot;/>
      • < xsd:element name =&quot; ExpiryDate &quot; type =&quot; xsd:date &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • < xsd:simpleType name =&quot; cardTypeRestriction &quot;>
      • < xsd:restriction base =&quot; xsd:string &quot;>
      • < xsd:enumeration value =&quot; VISA &quot;/>
      • < xsd:enumeration value =&quot; MASTER &quot;/>
      • < xsd:enumeration value =&quot; AMEX &quot;/>
      • </ xsd:restriction >
      • </ xsd:simpleType >
      • < xsd:complexType name =&quot; chequeType &quot;>
      • < xsd:sequence >
      • < xsd:element name =&quot; ChequeNumber &quot; type =&quot; xsd:positiveInteger &quot;/>
      • < xsd:element name =&quot; IssuingBank &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; IssuingBranch &quot; type =&quot; xsd:string &quot;/>
      • < xsd:element name =&quot; Dated &quot; type =&quot; xsd:date &quot;/>
      • </ xsd:sequence >
      • </ xsd:complexType >
      • </ xsd:schema >
    • Exercise – 2
      • Keep information about the scores of a cricket team in a match in the following form:
        • Team name
        • Opposition team name
        • Innings (1 or 2)
          • Batsman’s details
            • Batting position (1 to 11)
            • Batsman name
            • How out (either Caught, Bowled, LBW, or Not Out)
            • Bowler’s name
            • Runs scored (0 to 400)
    • XML Schemas: Case Study
    • Case Study on Schema – Sample XML Document
      • <?xml version=“1.0”>
      • <company ccode=“XYZ Corp Ltd”>
      • <chairman>Rajesh</chairman>
      • <department>
      • <manager>Hari</manager>
      • <assistant>Madhuri</assistant>
      • <role-description>Administration</role-description>
      • </department>
      • <department>
      • <manager>Vivek</manager>
      • <assistant>Bhavna</assistant>
      • <role-description>Training</role-description>
      • </department>
      • </company>
    • Case Study on Schema – Designing Schema
      • We need the following declaration in our schema file, after the <?xml …?> declaration:
        • <xsd:schema xmlns:xsd=“ http://www.w3.org/2000/10/XMLSchema ”>
    • Case Study –Schema
      • Write out the schema in a manner similar to the way the XML document is organized
      • So, start with a <company> root tag
        • This tag has attributes and sub-elements
        • Hence, it should be of type <complexType>
        • The other type ( <simpleType> ) is reserved for data types holding only values, but no attributes or sub-elements
        • To define the sub-elements, use the <sequence> tag
    • Case Study - Schema -> The structure so far
      • <xsd:element name=“company”>
      • <xsd:complexType>
      • <xsd:sequence>
      • Notes:
        • The <sequence> element defines the order of the child elements
        • Other options are <choice> and <all> , discussed later
        • Let us now define the sub-elements of the company root element
    • Case Study - Schema -> Adding Sub-Elements
      • <xsd:element name=“chairman” type=“xsd:string”/>
      • Defines the first sub-element
      • Now, define the department sub-element and its sub-elements
      • <xsd:element name=“department” minOccurs=“0” maxOccurs=“unbounded”>
      • <xsd:sequence>
      • <xsd:complexType>
    • Case Study - Schema -> Adding Sub-Sub-Elements
      • Now, define the sub-elements of the department tag
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=“manager” type=“xsd:string”/>
      • <xsd:element name=“assistant” type=“xsd:string” minOccurs=“0” maxOccurs=“unbounded”/>
      • <xsd:element name=“role-description” type=“xsd:string”/>
      • </xsd:sequence>
      • </xsd:complexType>
    • Case Study - Schema -> Closing the Root Tag
      • Why have we not closed the root tag <company> ?
        • Because, we want to define an attribute for it
      • <xsd:attribute name=“ccode” type=“xsd:string”/>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
      • Note: Attribute definitions must always follow the element definitions.
    • Case Study - Schema -> The Complete Schema Code
      • <?xml version=&quot;1.0&quot;?>
      • <xsd:schema xmlns=&quot;http://www.w3.org/2000/10/XMLSchema&quot;>
      • <xsd:element name=&quot;company&quot;>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=“chairman” type=“xsd:string”/>
      • <xsd:element name=“department” minOccurs=“0” maxOccurs=“unbounded”>
      • <xsd:complexType>
      • <xsd:sequence>
      • <xsd:element name=“manager” type=“xsd:string”/>
      • <xsd:element name=“assistant” type=“xsd:string” minOccurs=“0” maxOccurs=“unbounded”/>
      • <xsd:element name=“role-description” type=“xsd:string”/>
      • </xsd:sequence>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:sequence>
      • <xsd:attribute name=“ccode” type=“xsd:string”/>
      • </xsd:complexType>
      • </xsd:element>
      • </xsd:schema>
    • Thank you! Any Questions?