SlideShare a Scribd company logo
1 of 16
XML Schemas CIS-189
Alternative to DTD’s as way to define structure Defining a language (vocabulary) Structure may be also referred to as vocabulary Ensures that data matches specifications Serves as basis for other XML-related technologies XML Schemas
Use XML for definition Doesn’t have separate structure like DTD’s Schema must be well-formed Provides for built-in and user-defined data types Can be easily reused Supports concepts such as inheritance One object is based on another A definition may be reused and modified without starting from scratch each time Working with Schemas
Support World Wide Web Namespace recommendations A namespace allows the same name (data type/definition) to be used in different Schemas and properly understood A course may be defined as department, course number, title, credits and prerequisites for the College Catalog A course for grading may be defined as department, course number and credits for a grading application Using namespaces allows both definitions to be used, by specifying if working with a course defined for the catalog or grading Schemas and Namespaces
Schema file uses an .xsd extension Root element is the schema Can nest all elements within the schema Everything is hierarchical OR Can have multiple elements as child elements of the schema root Allows use of a definition any place in the document (data) file Elements which are child elements of schema are global Creating Schemas
Allows more specificity than DTD’s Can specify dates, numbers, ranges Datatypes fall into two categories: Simple deals with basic values Complex describes more intricate values or structures Schema Datatypes
Simple data type is about text, numbers, date Sometime referred to as “primitives” Data types built in to Schema vocabulary (and related elements, attributes) are in the XML Schema namespace Need reference to namespace to have valid XML specified (where to find the defined type) Elements that are Simple Datatypes don’t have attributes Including an attribute makes an element Complex Simple Datatypes
String Boolean Numbers Integer Decimal Float Double Custom (simpleType) Date/time Time TimeInstant Duration Date Month Year Century RecurringDate RecurringDay Simple Types
<?xml version=“1.0”?> <xsd:schemaxmlns:xsd=“http://www.w3.org/2001/XMLSchema”> 	<xsd:element name=“department” type=“xsd:string”/> 	<xsd:element name=“number” type=“xsd:string”/> 	<xsd:element name=“title” type=“xsd:string”/> 	<xsd:element name=“credits” type=“xsd:integer”/> </schema> Schema Defining a Course Using Simple Types xmlns:xsd= specifies where the namespace can be found xsd: specifies the namespace where the definition exists Assign attribute values to create the definition of an element in your vocabulary
The simpleType allows customization of base types Can create limits on values Specify ranges Specify lists Degrees is a simple type, based on string: <xsd:simpleType=“Degrees”> 	<xsd:restriction base=“xsd:string”> 		<xsd:enumeration value=“AA” /> 		<xsd:enumeration value=“AS” /> 	</xsd: restriction> </xsd:simpleType> Defining (Simple) Datatypes
Complex types allows combination of different elements and specification of order, new data types Can create an element Course which is comprised of simple types A valid Course must have department, number, title and credits elements in order: <xsd:element name=“course”> 	<xsd:complexType> 		<xsd:sequence> 		<xsd:element name=“department” type=“xsd:string”/> 		<xsd:element name=“number” type=“xsd:string”/> 		<xsd:element name=“title” type=“xsd:string”/> 		<xsd:element name=“credits” type=“xsd:integer”/> 		</xsd:sequence> 	</xsd:complexType> </xsd:element> ComplexDatatypes
When using a schema, need to create a reference from data (.xml) file Use either the schemaLocation or noNamespaceSchemaLocation attribute of the root element <course xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceShemaLocation=“course.xsd”> Using a Schema
Creating a simple type A phone number is text, up to 20 characters <xs:simpleType name="PhoneSimpleType“> 	<xs:restrictionbase="xs:string“> 		<xs:maxLength value="20" /> 	</xs:restriction> </xs:simpleType> Book Code – Employees.xsd
Using a simple type: The element homephone uses the simple type “PhoneSimpleType” to limit phone numbers to a maximum of 20 characters <xs:element name="homephone" type="PhoneSimpleType" /> Book Code – Employees.xsd 2
Employees is a complex type made of employee, which uses the EmployeeType <xs:element name="employees“> 	<xs:complexType> 	<xs:sequence> 		<xs:element name="employee" type="EmployeeType" minOccurs="0" maxOccurs="unbounded" /> 	</xs:sequence> </xs:complexType> </xs:element> Book Code – Employees.xsd 3
Setting the root element for a schema <?xml version="1.0" encoding="utf-8"?> <xs:schemaattributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> Book Code – Employees.xsd 4 xs becomes “shorthand” to refer to the Internet location for definitions; following element definitions all include that reference (xs)

More Related Content

What's hot (15)

Xml schema
Xml schemaXml schema
Xml schema
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
XSD
XSDXSD
XSD
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
XML Schema
XML SchemaXML Schema
XML Schema
 
DTD
DTDDTD
DTD
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 

Similar to XML schemas

Similar to XML schemas (20)

XML Schema.pptx
XML Schema.pptxXML Schema.pptx
XML Schema.pptx
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
advDBMS_XML.pptx
advDBMS_XML.pptxadvDBMS_XML.pptx
advDBMS_XML.pptx
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
 
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
DATA INTEGRATION (Gaining Access to Diverse Data).pptDATA INTEGRATION (Gaining Access to Diverse Data).ppt
DATA INTEGRATION (Gaining Access to Diverse Data).ppt
 
O9schema
O9schemaO9schema
O9schema
 
Schema
SchemaSchema
Schema
 
Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12Advanced Web Programming Chapter 12
Advanced Web Programming Chapter 12
 
XML_schema_Structure
XML_schema_StructureXML_schema_Structure
XML_schema_Structure
 
Xml session
Xml sessionXml session
Xml session
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 

More from Randy Riness @ South Puget Sound Community College

More from Randy Riness @ South Puget Sound Community College (20)

Stored procedures
Stored proceduresStored procedures
Stored procedures
 
3 sql overview
3 sql overview3 sql overview
3 sql overview
 
Normalization
NormalizationNormalization
Normalization
 
CIS160 final review
CIS160 final reviewCIS160 final review
CIS160 final review
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
CIS 245 Final Review
CIS 245 Final ReviewCIS 245 Final Review
CIS 245 Final Review
 
CIS145 Final Review
CIS145 Final ReviewCIS145 Final Review
CIS145 Final Review
 
Cis166 Final Review C#
Cis166 Final Review C#Cis166 Final Review C#
Cis166 Final Review C#
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
CIS245 sql
CIS245 sqlCIS245 sql
CIS245 sql
 
Cis245 Midterm Review
Cis245 Midterm ReviewCis245 Midterm Review
Cis245 Midterm Review
 
CSS
CSSCSS
CSS
 
XPath
XPathXPath
XPath
 
XSLT Overview
XSLT OverviewXSLT Overview
XSLT Overview
 
Views
ViewsViews
Views
 
CIS282 Midterm review
CIS282 Midterm reviewCIS282 Midterm review
CIS282 Midterm review
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
CIS 145 test 1 review
CIS 145 test 1 reviewCIS 145 test 1 review
CIS 145 test 1 review
 
Document type definitions part 2
Document type definitions part 2Document type definitions part 2
Document type definitions part 2
 
Document type definitions part 1
Document type definitions part 1Document type definitions part 1
Document type definitions part 1
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

XML schemas

  • 2. Alternative to DTD’s as way to define structure Defining a language (vocabulary) Structure may be also referred to as vocabulary Ensures that data matches specifications Serves as basis for other XML-related technologies XML Schemas
  • 3. Use XML for definition Doesn’t have separate structure like DTD’s Schema must be well-formed Provides for built-in and user-defined data types Can be easily reused Supports concepts such as inheritance One object is based on another A definition may be reused and modified without starting from scratch each time Working with Schemas
  • 4. Support World Wide Web Namespace recommendations A namespace allows the same name (data type/definition) to be used in different Schemas and properly understood A course may be defined as department, course number, title, credits and prerequisites for the College Catalog A course for grading may be defined as department, course number and credits for a grading application Using namespaces allows both definitions to be used, by specifying if working with a course defined for the catalog or grading Schemas and Namespaces
  • 5. Schema file uses an .xsd extension Root element is the schema Can nest all elements within the schema Everything is hierarchical OR Can have multiple elements as child elements of the schema root Allows use of a definition any place in the document (data) file Elements which are child elements of schema are global Creating Schemas
  • 6. Allows more specificity than DTD’s Can specify dates, numbers, ranges Datatypes fall into two categories: Simple deals with basic values Complex describes more intricate values or structures Schema Datatypes
  • 7. Simple data type is about text, numbers, date Sometime referred to as “primitives” Data types built in to Schema vocabulary (and related elements, attributes) are in the XML Schema namespace Need reference to namespace to have valid XML specified (where to find the defined type) Elements that are Simple Datatypes don’t have attributes Including an attribute makes an element Complex Simple Datatypes
  • 8. String Boolean Numbers Integer Decimal Float Double Custom (simpleType) Date/time Time TimeInstant Duration Date Month Year Century RecurringDate RecurringDay Simple Types
  • 9. <?xml version=“1.0”?> <xsd:schemaxmlns:xsd=“http://www.w3.org/2001/XMLSchema”> <xsd:element name=“department” type=“xsd:string”/> <xsd:element name=“number” type=“xsd:string”/> <xsd:element name=“title” type=“xsd:string”/> <xsd:element name=“credits” type=“xsd:integer”/> </schema> Schema Defining a Course Using Simple Types xmlns:xsd= specifies where the namespace can be found xsd: specifies the namespace where the definition exists Assign attribute values to create the definition of an element in your vocabulary
  • 10. The simpleType allows customization of base types Can create limits on values Specify ranges Specify lists Degrees is a simple type, based on string: <xsd:simpleType=“Degrees”> <xsd:restriction base=“xsd:string”> <xsd:enumeration value=“AA” /> <xsd:enumeration value=“AS” /> </xsd: restriction> </xsd:simpleType> Defining (Simple) Datatypes
  • 11. Complex types allows combination of different elements and specification of order, new data types Can create an element Course which is comprised of simple types A valid Course must have department, number, title and credits elements in order: <xsd:element name=“course”> <xsd:complexType> <xsd:sequence> <xsd:element name=“department” type=“xsd:string”/> <xsd:element name=“number” type=“xsd:string”/> <xsd:element name=“title” type=“xsd:string”/> <xsd:element name=“credits” type=“xsd:integer”/> </xsd:sequence> </xsd:complexType> </xsd:element> ComplexDatatypes
  • 12. When using a schema, need to create a reference from data (.xml) file Use either the schemaLocation or noNamespaceSchemaLocation attribute of the root element <course xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceShemaLocation=“course.xsd”> Using a Schema
  • 13. Creating a simple type A phone number is text, up to 20 characters <xs:simpleType name="PhoneSimpleType“> <xs:restrictionbase="xs:string“> <xs:maxLength value="20" /> </xs:restriction> </xs:simpleType> Book Code – Employees.xsd
  • 14. Using a simple type: The element homephone uses the simple type “PhoneSimpleType” to limit phone numbers to a maximum of 20 characters <xs:element name="homephone" type="PhoneSimpleType" /> Book Code – Employees.xsd 2
  • 15. Employees is a complex type made of employee, which uses the EmployeeType <xs:element name="employees“> <xs:complexType> <xs:sequence> <xs:element name="employee" type="EmployeeType" minOccurs="0" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> Book Code – Employees.xsd 3
  • 16. Setting the root element for a schema <?xml version="1.0" encoding="utf-8"?> <xs:schemaattributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> Book Code – Employees.xsd 4 xs becomes “shorthand” to refer to the Internet location for definitions; following element definitions all include that reference (xs)