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

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

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)