SlideShare a Scribd company logo
XML Schema XML http://yht4ever.blogspot.com [email_address] B070066 - NIIT Quang Trung 08/2007
Contents Create group of element and attribute Attribute in XML Schemas Elements in XML Schemas Data Types in XML Schemas Introduction to XML Schema
Introduction to XML Schema An XML schema defines the list of elements and attributes that can be used in an XML document. It also specifies the order in which these elements appear in the XML document, and their data types.  Microsoft has developed the XML Schema Definition (XSD) language to define the schema of an XML document
Advantages of XML Schema XSD provides more control over the type of data that can be assigned to elements and attributes as compared to DTD.  XSD enables you to create your own data types.  XSD enables you to specify restrictions on data.  The syntax for defining an XSD is the same as the syntax used for XML documents.  XML schema content models can be used to validate mixed content, which cannot be validated by DTD content models. XML schema is extensible.
Data Types in XML Schemas A data type specifies the type of content that an element can hold.  XSD provides a list of predefined data types. These data types can be classified as follows: Primitive: Are the fundamental data types of XSD.  Derived: Are defined by using other data types called base types.  Atomic: Are primitive or derived data types that cannot be broken down into smaller units.  List: Are derived data types that contain a set of values of atomic data types.  Union: Are derived from the atomic and list data types.
Elements in XML Schemas There are two types of elements, simple and complex. Simple Element A simple element does not contain any child elements or attributes.  The syntax for declaring a simple element is as follows: <xsd:element name=&quot;element-name&quot; type=&quot;data type&quot; minOccurs=&quot;nonNegativeInteger&quot; maxOccurs=&quot;nonNegativeInteger|unbounded&quot;/>
Example <PRODUCTDATA> <PRODUCT PRODUCTID=&quot;P001&quot; CATEGORY=&quot;BOOKS&quot;> <PRODUCTNAME>Gone With the Wind</PRODUCTNAME> <DESCRIPTION> The backdrop of this book is the American  Civil War</DESCRIPTION> <PRICE>25.00</PRICE>   <QUANTITY>35</QUANTITY> </PRODUCT> </PRODUCTDATA> <xsd:element name=&quot;PRODUCTNAME&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DESCRIPTION&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;PRICE&quot; type=&quot;xsd:positiveInteger&quot;/> <xsd:element name=&quot;QUANTITY&quot; type=&quot;xsd:nonNegativeInteger&quot;/>
Elements in XML Schemas (cont.) Complex Element A complex element contains other elements, attributes, and mixed content. The syntax to define a complex data type is as follows: <xsd:complexType name=&quot;data type name&quot;> Content model declaration </xsd:complexType>
Elements in XML Schemas (cont.) Defining a New Simple Data Type Based on an Existing Simple Data Type <xsd:simpleType name=&quot;phoneno&quot;> <xsd:restriction base=&quot;xsd:string&quot;> <xsd:length value=&quot;8&quot;/> <xsd:pattern value=&quot;\d{3}-\d{4}&quot;/> </xsd:restriction> </xsd:simpleType>
Elements in XML Schemas (cont.) <xsd:simpleType name=&quot;num&quot;> <xsd:restriction base=&quot;xsd:positiveInteger&quot;> <xsd:maxInclusive value=&quot;400&quot;/> <xsd:minInclusive value=&quot;10&quot;/> </xsd:restriction> </xsd:simpleType>
Elements in XML Schemas (cont.) The element to be declared as a complex type must be associated with a complex data type. A complex type element can be associated with a complex data type using the syntax:  <xsd:element name=“ElementName&quot; type=“ComplexDataType&quot;/> In the preceding syntax,  ElementName  is the name of the element   and  ComplexDataType  is the complex data type declared earlier.
Elements in XML Schemas (cont.) <xsd:complexType name=&quot;prdt&quot;> <xsd:sequence> <xsd:element name=&quot;PRODUCTNAME&quot;  type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DESCRIPTION&quot;  type=&quot;xsd:string&quot;/> <xsd:element name=&quot;PRICE&quot;  type=&quot;xsd:positiveInteger&quot;/> <xsd:element name=&quot;QUANTITY&quot;  type=&quot;xsd:nonNegativeInteger&quot;/> </xsd:sequence> </xsd:complexType>
Review Simple element declaration Complex element declaration Simple type declaration Complex type declaration
Declaring Attributes in a Schema  Attribute declarations can be defined in two ways: Simple Type Definitions  Global Attribute Declarations The syntax for declaring an attribute in XSD is as follows: <attribute name=&quot;attributename&quot;  ref=&quot;attributename&quot; type=&quot;datatypename&quot; use=&quot;value&quot;  value=&quot;value&quot;> </attribute>  Consists of various attributes: name: Used to specify the name of a user-defined attribute.  ref: Used to refer to a user-defined attribute declared either in the same or in any other XSD document.
Declaring Attributes in a Schema (cont.) Consists of various attributes (cont.): type: Takes a value that specifies the data type of the user-defined attribute.  use: Specifies the way in which an attribute can be used in an XML document. optional default required fixed
Declaring Attributes in a Schema (cont.) Global Attributes  Are declared outside all element declarations.  Facilitate attribute reusability. For such attributes, the schema element is the parent element. For example <xsd:schema> <xsd:attribute name=&quot;NAME&quot; type=&quot;xsd:string&quot;/ </xsd:schema>
Declaring Attributes in a Schema (cont.) In order to restrict values that can be assigned to an attribute: Declare the attribute and associate it with a user-defined simple data type. Create a simple data type by using the XSD simpleType element.  Use the XSD restriction element within the simpleType element to restrict the values that can be assigned to the elements or attributes that use the simple data type.
Exercises Create a Schema for music.xml
Create groups of elements and attributes Feature of creating grouped elements and attributes facilitates the following tasks: Creating a reusable group of elements and attributes.  Selecting  a single element from a group.  Specifying the sequence of elements. XSD provides the following elements to group user-defined elements and attributes:  sequence  group  choice  all  attributeGroup
Create groups of elements and attributes (cont.) Sequence Ensures that the elements declared within the opening and closing tags appear in a specific order. <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&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:element name=&quot;DESIG&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DEPARTMENT&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Create groups of elements and attributes (cont.) The group Element  Grouping of elements is beneficial when you want a set of related elements to be referred using a common name.  The syntax for declaring a group element is as follows: <group maxOccurs=&quot;nonNegetiveInteger | unbounded“ minOccurs=&quot;nonNegetiveInteger&quot; name=&quot;NCName&quot; ref=&quot;QName&quot;> </group>
Create groups of elements and attributes (cont.) Example <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:group name=&quot;empname&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;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&quot;> <xsd:sequence> <xsd:group ref=&quot;empname&quot;/> <xsd:element name=&quot;ADDRESS&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
Create groups of elements and attributes (cont.) The choice Element  Enables the selection of a single option from multiple options. Allows only one of the elements contained in the group to be present within the parent element.  The syntax for declaring a choice element is as follows: <choice id=&quot;ID&quot; maxOccurs=&quot;nonNegativeInteger | unbounded&quot; minOccurs=&quot;nonNegativeInteger&quot;> </choice>
Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;CUSTOMER&quot; type=&quot;custtype&quot;/> <xsd:complexType name=&quot;custtype&quot;> <xsd:sequence> <xsd:group ref=&quot;custname&quot;/> <xsd:element name=&quot;ADDRESS&quot; type=&quot;addtype&quot;/> </xsd:sequence> </xsd:complexType> <xsd:complexType name=&quot;addtype&quot;> <xsd:choice> <xsd:element name=&quot;RESIDENCE&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;OFFICE&quot; type=&quot;xsd:string&quot;/> </xsd:choice> </xsd:complexType> <xsd:group name=&quot;custname&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:schema>
Create groups of elements and attributes (cont.) The all Element  Enables to use the child elements in any order. The syntax for using the all element: <all maxOccurs=&quot;positiveInteger&quot; minOccurs=&quot; 0 | 1 &quot;> </all>
Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot; /> <xsd:complexType name=&quot;emptype&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:element name=&quot;DESIG&quot;  type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DEPARTMENT&quot;  type=&quot;xsd:string&quot;/> </xsd:all> </xsd:complexType> </xsd:schema>
Create groups of elements and attributes (cont.) The attributeGroup Element  Enables to group attributes that can be reused with different elements. The syntax of the attributeGroup element is as follows: <attributeGroup> attribute1 attribute2   : </attributeGroup>
Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&quot;> <xsd:group ref=&quot;empname&quot;/> <xsd:attributeGroup ref=&quot;depdesig&quot;/> </xsd:complexType> <xsd:group name=&quot;empname&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:attributeGroup name=&quot;depdesig&quot;> <xsd:attribute name=&quot;DEPARTMENT&quot; type=&quot;xsd:string&quot;/> <xsd:attribute name=&quot;DESIGNATION&quot; type=&quot;xsd:string&quot;/> </xsd:attributeGroup> </xsd:schema>
To be continued…
Reference XML How to program http://www.w3.org Teach Yourself XML in 21 Days, 3 rd  Edition Learning XML, 2 nd  Edition XML tutorial http://www.w3schools.com/w3c/
Q&A Feel free to post questions at  http://yht4ever.blogspot.com . or email to:  [email_address]  or  [email_address]
http://yht4ever.blogspot.com Thank You !

More Related Content

What's hot (20)

PPTX
Dynamic HTML (DHTML)
Himanshu Kumar
 
PPTX
Xml presentation
Miguel Angel Teheran Garcia
 
PPT
Introduction to XML
yht4ever
 
PDF
Xml schema
Prabhakaran V M
 
PPTX
XML DTD and Schema
hamsa nandhini
 
PPTX
XML Document Object Model (DOM)
BOSS Webtech
 
PPTX
Introduction to xml
Gtu Booker
 
PPTX
XML, DTD & XSD Overview
Pradeep Rapolu
 
PPTX
Xml ppt
seemadav1
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPTX
Relational Data Model Introduction
Nishant Munjal
 
PPTX
HTML: Tables and Forms
BG Java EE Course
 
PPTX
Java script
Abhishek Kesharwani
 
PPTX
HTML frames and HTML forms
Nadine Cruz
 
PPSX
Functional dependency
Dashani Rajapaksha
 
PPTX
Css box-model
Webtech Learning
 
PPTX
Ado.Net Tutorial
prabhu rajendran
 
Dynamic HTML (DHTML)
Himanshu Kumar
 
Xml presentation
Miguel Angel Teheran Garcia
 
Introduction to XML
yht4ever
 
Xml schema
Prabhakaran V M
 
XML DTD and Schema
hamsa nandhini
 
XML Document Object Model (DOM)
BOSS Webtech
 
Introduction to xml
Gtu Booker
 
XML, DTD & XSD Overview
Pradeep Rapolu
 
Xml ppt
seemadav1
 
Document Object Model (DOM)
GOPAL BASAK
 
Relational Data Model Introduction
Nishant Munjal
 
HTML: Tables and Forms
BG Java EE Course
 
Java script
Abhishek Kesharwani
 
HTML frames and HTML forms
Nadine Cruz
 
Functional dependency
Dashani Rajapaksha
 
Css box-model
Webtech Learning
 
Ado.Net Tutorial
prabhu rajendran
 

Similar to XML Schema (20)

PPT
Xml Schema
vikram singh
 
PPTX
XML Schema
Kumar
 
PPT
3 xml namespaces and xml schema
gauravashq
 
PPTX
35 schemas
mavilym
 
PPT
Xsd examples
Bình Trọng Án
 
PPT
02 xml schema
Baskarkncet
 
PDF
XSD Incomplete Overview Draft
Pedro De Almeida
 
ODP
SCDJWS 1. xml schema
Francesco Ierna
 
PPTX
Service Oriented Architecture-Unit-1-XML Schema
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
PPTX
XML SCHEMAS
SaraswathiRamalingam
 
PPT
O9schema
Ergoclicks
 
PPT
Schema
Ergoclicks
 
DOC
Xsd
xavier john
 
PDF
IQPC Canada XML 2001: How to develop Syntax and XML Schema
Ted Leung
 
PPTX
Xml part4
NOHA AW
 
PPT
XSD
Kunal Gaind
 
PPTX
XML-Schema-Elements_Types_Attributes.pptx
AkshayKumar100378
 
PPTX
XML Fundamentals
Andres Felipe Rincon Rodriguez
 
Xml Schema
vikram singh
 
XML Schema
Kumar
 
3 xml namespaces and xml schema
gauravashq
 
35 schemas
mavilym
 
Xsd examples
Bình Trọng Án
 
02 xml schema
Baskarkncet
 
XSD Incomplete Overview Draft
Pedro De Almeida
 
SCDJWS 1. xml schema
Francesco Ierna
 
Service Oriented Architecture-Unit-1-XML Schema
Ramco Institute of Technology, Rajapalayam, Tamilnadu, India
 
O9schema
Ergoclicks
 
Schema
Ergoclicks
 
IQPC Canada XML 2001: How to develop Syntax and XML Schema
Ted Leung
 
Xml part4
NOHA AW
 
XML-Schema-Elements_Types_Attributes.pptx
AkshayKumar100378
 
Ad

More from yht4ever (11)

PPTX
Applications of SOA and Web Services in Grid Computing
yht4ever
 
PPT
ERD - Database Design
yht4ever
 
PPT
Web Page Authoring 1
yht4ever
 
PPT
Introduction to HTML
yht4ever
 
PPT
Introduction to HTML
yht4ever
 
PPT
Document Object Model
yht4ever
 
PPT
XPath - XML Path Language
yht4ever
 
PPT
Rendering XML Document
yht4ever
 
PPT
Rendering XML Documents
yht4ever
 
PPT
Document Type Definition
yht4ever
 
PPT
GUI Programming In Java
yht4ever
 
Applications of SOA and Web Services in Grid Computing
yht4ever
 
ERD - Database Design
yht4ever
 
Web Page Authoring 1
yht4ever
 
Introduction to HTML
yht4ever
 
Introduction to HTML
yht4ever
 
Document Object Model
yht4ever
 
XPath - XML Path Language
yht4ever
 
Rendering XML Document
yht4ever
 
Rendering XML Documents
yht4ever
 
Document Type Definition
yht4ever
 
GUI Programming In Java
yht4ever
 
Ad

Recently uploaded (20)

PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

XML Schema

  • 1. XML Schema XML http://yht4ever.blogspot.com [email_address] B070066 - NIIT Quang Trung 08/2007
  • 2. Contents Create group of element and attribute Attribute in XML Schemas Elements in XML Schemas Data Types in XML Schemas Introduction to XML Schema
  • 3. Introduction to XML Schema An XML schema defines the list of elements and attributes that can be used in an XML document. It also specifies the order in which these elements appear in the XML document, and their data types. Microsoft has developed the XML Schema Definition (XSD) language to define the schema of an XML document
  • 4. Advantages of XML Schema XSD provides more control over the type of data that can be assigned to elements and attributes as compared to DTD. XSD enables you to create your own data types. XSD enables you to specify restrictions on data. The syntax for defining an XSD is the same as the syntax used for XML documents. XML schema content models can be used to validate mixed content, which cannot be validated by DTD content models. XML schema is extensible.
  • 5. Data Types in XML Schemas A data type specifies the type of content that an element can hold. XSD provides a list of predefined data types. These data types can be classified as follows: Primitive: Are the fundamental data types of XSD. Derived: Are defined by using other data types called base types. Atomic: Are primitive or derived data types that cannot be broken down into smaller units. List: Are derived data types that contain a set of values of atomic data types. Union: Are derived from the atomic and list data types.
  • 6. Elements in XML Schemas There are two types of elements, simple and complex. Simple Element A simple element does not contain any child elements or attributes. The syntax for declaring a simple element is as follows: <xsd:element name=&quot;element-name&quot; type=&quot;data type&quot; minOccurs=&quot;nonNegativeInteger&quot; maxOccurs=&quot;nonNegativeInteger|unbounded&quot;/>
  • 7. Example <PRODUCTDATA> <PRODUCT PRODUCTID=&quot;P001&quot; CATEGORY=&quot;BOOKS&quot;> <PRODUCTNAME>Gone With the Wind</PRODUCTNAME> <DESCRIPTION> The backdrop of this book is the American Civil War</DESCRIPTION> <PRICE>25.00</PRICE> <QUANTITY>35</QUANTITY> </PRODUCT> </PRODUCTDATA> <xsd:element name=&quot;PRODUCTNAME&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DESCRIPTION&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;PRICE&quot; type=&quot;xsd:positiveInteger&quot;/> <xsd:element name=&quot;QUANTITY&quot; type=&quot;xsd:nonNegativeInteger&quot;/>
  • 8. Elements in XML Schemas (cont.) Complex Element A complex element contains other elements, attributes, and mixed content. The syntax to define a complex data type is as follows: <xsd:complexType name=&quot;data type name&quot;> Content model declaration </xsd:complexType>
  • 9. Elements in XML Schemas (cont.) Defining a New Simple Data Type Based on an Existing Simple Data Type <xsd:simpleType name=&quot;phoneno&quot;> <xsd:restriction base=&quot;xsd:string&quot;> <xsd:length value=&quot;8&quot;/> <xsd:pattern value=&quot;\d{3}-\d{4}&quot;/> </xsd:restriction> </xsd:simpleType>
  • 10. Elements in XML Schemas (cont.) <xsd:simpleType name=&quot;num&quot;> <xsd:restriction base=&quot;xsd:positiveInteger&quot;> <xsd:maxInclusive value=&quot;400&quot;/> <xsd:minInclusive value=&quot;10&quot;/> </xsd:restriction> </xsd:simpleType>
  • 11. Elements in XML Schemas (cont.) The element to be declared as a complex type must be associated with a complex data type. A complex type element can be associated with a complex data type using the syntax: <xsd:element name=“ElementName&quot; type=“ComplexDataType&quot;/> In the preceding syntax, ElementName is the name of the element and ComplexDataType is the complex data type declared earlier.
  • 12. Elements in XML Schemas (cont.) <xsd:complexType name=&quot;prdt&quot;> <xsd:sequence> <xsd:element name=&quot;PRODUCTNAME&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DESCRIPTION&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;PRICE&quot; type=&quot;xsd:positiveInteger&quot;/> <xsd:element name=&quot;QUANTITY&quot; type=&quot;xsd:nonNegativeInteger&quot;/> </xsd:sequence> </xsd:complexType>
  • 13. Review Simple element declaration Complex element declaration Simple type declaration Complex type declaration
  • 14. Declaring Attributes in a Schema Attribute declarations can be defined in two ways: Simple Type Definitions Global Attribute Declarations The syntax for declaring an attribute in XSD is as follows: <attribute name=&quot;attributename&quot; ref=&quot;attributename&quot; type=&quot;datatypename&quot; use=&quot;value&quot; value=&quot;value&quot;> </attribute> Consists of various attributes: name: Used to specify the name of a user-defined attribute. ref: Used to refer to a user-defined attribute declared either in the same or in any other XSD document.
  • 15. Declaring Attributes in a Schema (cont.) Consists of various attributes (cont.): type: Takes a value that specifies the data type of the user-defined attribute. use: Specifies the way in which an attribute can be used in an XML document. optional default required fixed
  • 16. Declaring Attributes in a Schema (cont.) Global Attributes Are declared outside all element declarations. Facilitate attribute reusability. For such attributes, the schema element is the parent element. For example <xsd:schema> <xsd:attribute name=&quot;NAME&quot; type=&quot;xsd:string&quot;/ </xsd:schema>
  • 17. Declaring Attributes in a Schema (cont.) In order to restrict values that can be assigned to an attribute: Declare the attribute and associate it with a user-defined simple data type. Create a simple data type by using the XSD simpleType element. Use the XSD restriction element within the simpleType element to restrict the values that can be assigned to the elements or attributes that use the simple data type.
  • 18. Exercises Create a Schema for music.xml
  • 19. Create groups of elements and attributes Feature of creating grouped elements and attributes facilitates the following tasks: Creating a reusable group of elements and attributes. Selecting a single element from a group. Specifying the sequence of elements. XSD provides the following elements to group user-defined elements and attributes: sequence group choice all attributeGroup
  • 20. Create groups of elements and attributes (cont.) Sequence Ensures that the elements declared within the opening and closing tags appear in a specific order. <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&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:element name=&quot;DESIG&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DEPARTMENT&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
  • 21. Create groups of elements and attributes (cont.) The group Element Grouping of elements is beneficial when you want a set of related elements to be referred using a common name. The syntax for declaring a group element is as follows: <group maxOccurs=&quot;nonNegetiveInteger | unbounded“ minOccurs=&quot;nonNegetiveInteger&quot; name=&quot;NCName&quot; ref=&quot;QName&quot;> </group>
  • 22. Create groups of elements and attributes (cont.) Example <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:group name=&quot;empname&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;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&quot;> <xsd:sequence> <xsd:group ref=&quot;empname&quot;/> <xsd:element name=&quot;ADDRESS&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema>
  • 23. Create groups of elements and attributes (cont.) The choice Element Enables the selection of a single option from multiple options. Allows only one of the elements contained in the group to be present within the parent element. The syntax for declaring a choice element is as follows: <choice id=&quot;ID&quot; maxOccurs=&quot;nonNegativeInteger | unbounded&quot; minOccurs=&quot;nonNegativeInteger&quot;> </choice>
  • 24. Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;CUSTOMER&quot; type=&quot;custtype&quot;/> <xsd:complexType name=&quot;custtype&quot;> <xsd:sequence> <xsd:group ref=&quot;custname&quot;/> <xsd:element name=&quot;ADDRESS&quot; type=&quot;addtype&quot;/> </xsd:sequence> </xsd:complexType> <xsd:complexType name=&quot;addtype&quot;> <xsd:choice> <xsd:element name=&quot;RESIDENCE&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;OFFICE&quot; type=&quot;xsd:string&quot;/> </xsd:choice> </xsd:complexType> <xsd:group name=&quot;custname&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:schema>
  • 25. Create groups of elements and attributes (cont.) The all Element Enables to use the child elements in any order. The syntax for using the all element: <all maxOccurs=&quot;positiveInteger&quot; minOccurs=&quot; 0 | 1 &quot;> </all>
  • 26. Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot; /> <xsd:complexType name=&quot;emptype&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:element name=&quot;DESIG&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;DEPARTMENT&quot; type=&quot;xsd:string&quot;/> </xsd:all> </xsd:complexType> </xsd:schema>
  • 27. Create groups of elements and attributes (cont.) The attributeGroup Element Enables to group attributes that can be reused with different elements. The syntax of the attributeGroup element is as follows: <attributeGroup> attribute1 attribute2 : </attributeGroup>
  • 28. Create groups of elements and attributes (cont.) <xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;> <xsd:element name=&quot;EMPLOYEE&quot; type=&quot;emptype&quot;/> <xsd:complexType name=&quot;emptype&quot;> <xsd:group ref=&quot;empname&quot;/> <xsd:attributeGroup ref=&quot;depdesig&quot;/> </xsd:complexType> <xsd:group name=&quot;empname&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:attributeGroup name=&quot;depdesig&quot;> <xsd:attribute name=&quot;DEPARTMENT&quot; type=&quot;xsd:string&quot;/> <xsd:attribute name=&quot;DESIGNATION&quot; type=&quot;xsd:string&quot;/> </xsd:attributeGroup> </xsd:schema>
  • 30. Reference XML How to program http://www.w3.org Teach Yourself XML in 21 Days, 3 rd Edition Learning XML, 2 nd Edition XML tutorial http://www.w3schools.com/w3c/
  • 31. Q&A Feel free to post questions at http://yht4ever.blogspot.com . or email to: [email_address] or [email_address]