SlideShare une entreprise Scribd logo
1  sur  55
XML SCHEMAS
Tutorial 4
LIMITATION OF DTD
• DTD has limitation on the number of data type can be used.
• Can not recognize the namespace.
SCHEMAS
● A schema is an XML document that defines the content and structure of one or
more XML documents.
● The XML document that will be validated is called the instance document.
● Why Use an XML Schema?
● With XML Schema, your XML files can carry a description of its own
format.
COMPARING SCHEMASAND DTDS
XML SCHEMA V.S DTD
• XML Schemas are More Powerful than DTD:
• XML Schemas are written in XML.
• XML Schema supports a collection of built-in data types and allows
programmers to define their own data types.
• XML Schemas support data types.
• XML Schemas support namespaces.
STARTING A SCHEMA FILE
• A schema is always placed in a separate XML document that is referenced
by the instance document.
• A file written in XML Schema has the extension .xsd
• Since the Schema file is actually an XML file, it must start with an XML
declaration.
• The root element in any XML Schema document is the schema element ,
and it must declare a namespace for the XML Schema.
<?xml version=“1.0” encoding=“UTF=8”?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
schema content
</xs:schema>
ELEMENTSANDATTRIBUTES OFTHE PATIENTS DOCUMENT
SCHEMATYPES
XML Schema recognize two categories of element types that are:
1. A complex type element has one or more attributes, or is the parent to one or more child
elements.
2. A simple type element contains only character data and has no attributes.
SCHEMATYPES
ELEMENTSANDATTRIBUTES OFTHE PATIENTS DOCUMENT
1- SIMPLE TYPE
ELEMENTS
SIMPLE TYPE ELEMENTS
• Use the following syntax to declare a simple type element in XML Schema:
<xs:element name=“name” type =“xs:type”/>
● Here, name is the name of the element in the instance document and type
is the datatype of the element.
● XML Schema tags must be qualified with the namespace prefix.
DECLARINGANATTRIBUTE
• An attribute is always a simple type. The syntax to define an attribute is
<xs:attribute name="name" type="xs:type” />
• Where name is the name of the attribute and type is the data type.
• You can also define a default value and a fixed value for the attribute:
<xs:attribute name="name" type="xs:type” default=“default value”
fixed=“fixed value" />
• The default and fixed attributes are optional.
* notice that we did not specify which element the attribute belongs to
2- COMPLEX TYPE
ELEMENTS
COMPLEX TYPE ELEMENTS
The basic structure for defining a complex type element with XML Schema is
<xs:element name="name">
<xs:complexType>
declarations
</xs:complexType>
</xs:element>
Where name is the name of the element and declarations are the declarations of the child elements or attributes
associated with the element.
COMPLEX TYPE ELEMENTS
Five complex type elements that usually appear in an instance document are
the following:
1–The element is an empty element and contains attributes only.
2–The element contains child elements only.
3–The element contains both child elements and attributes.
4–The element contains both child elements and text.
5–The element contains both attributes and text but no child element.
1- ELEMENTS WITHATTRIBUTES ONLY
• The code to declare an element with attributes only:
<xs:element name="name">
<xs:complexType>
attributes
</xs:complexType>
</xs:element>
• Where attributes is the set of declarations that define the attributes associated with the
element. For example, the empty element:
<subject name="Cynthia Dibbs" age="62" />
• The code for this complex type element has the following structure:
<xs:element name="subject">
<xs:complexType>
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="age" type="xs:string" />
</xs:complexType>
</xs:element>
SPECIFYING THE USE OFANATTRIBUTE
• An attribute may or may not be required with a particular element. To indicate whether an
attribute is required, you add the “use” attribute to the element declaration. The “use” attribute
has the following values:
• required: The attribute must always appear with the element
• optional: The use of the attribute is optional with the element
• prohibited: The attribute cannot be used with the element
• If you neglect to add the “use” attribute to an element declaration, the parser assumes that the
attribute is optional (meaning that “optional” is the default value for the “use” attribute).
• Example:
2-ELEMENTS WITH CHILD ELEMENTS ONLY
To define child elements, use the code structure:
<xs:element name="name">
<xs:complexType>
<xs:compositor>
elements
</xs:compositor>
</xs:complexType>
</xs:element>
Where elements is the list of simple type element declarations for each child element, and compositor defines
how the child elements are organized.
USING COMPOSITORS
XML Schema supports the following compositors:
• sequence: defines a specific order for the child elements
• choice: allows any one of the child elements to appear in the instance
document
• all: allows any of the child elements to appear in any order in the
instance document; however, they must appear at least once.
2-ELEMENTS WITH CHILD ELEMENTS ONLY(SEQUANCE EXAMPLE)
<element name="address">
<xs:complexType>
<xs:sequence>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="state" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
2-ELEMENTS WITH CHILD ELEMENTS ONLY
Example for choice compositor:
Example for all compositor:
COMBINING/NESTING COMPOSITORS
<xs:element name=“employee”>
<xs:complexType>
<xs:sequence>
<xs:element name=“name” type=“xs:string”/>
<xs:choice>
<xs:element name=“age” type=“xs:integer”/>
<xs:element name=“DOB” type=“xs:date”/>
</xs:choice>
<xs:all>
<xs:element name=“phone” type=“xs:string”/>
<xs:element name=“mobile” type=“xs:string”/>
<xs:element name=“email” type=“xs:string”/>
</xs:all>
</xs:sequence>
</xs:complexType>
</xs:element>
3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES
The code for a complex type element that contains both attributes and child elements is
<xs:element name="name">
<xs:complexType>
<xs:compositor>
Child Elements
</xs:compositor>
attributes
</xs:complexType>
</xs:element>
• The patient element contains two attributes (patID and onStudy) and seven child elements
(lastName, firstName, dateOfBirth, age, stage, comment, and performance.)
<xs:element name="patient">
<xs:complexType>
<xs:sequence>
<xs:element ref="lastName"/>
<xs:element ref="firstName"/>
<xs:element ref="dateOfBirth"/>
<xs:element ref="age"/>
<xs:element ref="stage"/>
<xs:element ref="comment" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="performance"/>
</xs:sequence>
<xs:attribute ref="patID" use="required"/>
<xs:attribute ref="onStudy" use="required"/>
</xs:complexType>
</xs:element>
3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES
3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES
4- SPECIFYING MIXED CONTENT
• To declare an element that contains child elements and text, add the “mixed”
attribute and set it to “true”.
• Note that XML Schema allows content text to appear before, between, and after any
of the child elements.
For example, the XML content:
<Summary>
Patient <Name>Cynthia Davis</Name> was enrolled in
the <Study>Tamoxifen Study</Study> on 8/15/2003.
</Summary>
Can be declared in the schema file using the following complex type:
<xs:element name="Summary">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="Name" type=“xs:string"/>
<xs:element name="Study" type=“xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
4- SPECIFYING MIXED CONTENT
5- ELEMENTS WITH TEXTANDATTRIBUTES BUT NO CHILD ELEMENTS
If an element contains text and attributes (but no child elements), the structure of the
complex type element is slightly different.
<xs:element name="name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:type">
attributes
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
For example, the empty element:
<performance scale="Karnofsky"> 0.81 </performance>
The code to associate the scale attribute with the performance element would
therefore be
<xs:element name="performance">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="scale"
type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
5- ELEMENTS WITH TEXTANDATTRIBUTES BUT NO CHILD
ELEMENTS
REFERENCINGAN ELEMENT ORATTRIBUTE
XML Schema allows for a great deal of flexibility in designing complex types. Rather
than nesting the attribute declaration within the element, you can create a reference to
it. The code to create a reference to an element or attribute declaration is
<xs:element ref="elemName" />
<xs:attribute ref="attName" />
Where elemName is the name used in an element declaration and attName is the name
used in an attribute declaration
EXAMPLE OFREFERENCINGAN ELEMENT ORATTRIBUTE
EXAMPLE OFREFERENCINGAN ELEMENT ORATTRIBUTE
SPECIFYING THE OCCURRENCE OFAN ITEM
• You can specify the occurrence of an element using the attributes minOccurs and maxOccurs.
• The minOccurs and maxOccurs can be any positive value
• The maxOccurs can have a value of “unbounded” for unlimited occurrences of the child
element
if minOccurs=”0” and maxOccurs is omitted ==> maxOccurs=”1” ==> the element is optional
if minOccurs=”x” and maxOccurs is omitted ==> maxOccurs=”x” (where x is any number greater
than 0)
if minOccurs and maxOccurs are both omitted ==> minOccurs=”1” and maxOccurs=”1”
*The default value for minOccurs and maxOccurs is “1”
“+” in DTDs is : minOccurs=“1” maxOccurs=“unbound”
“*” in DTDs is : minOccurs=“0” maxOccurs=“unbound”
“?” in DTDs is : minOccurs=“0” maxOccurs=“1”
SPECIFYING THE OCCURRENCE OFAN ITEM
SPECIFYING THE OCCURRENCE OFASEQUENCE
minOccurs and maxOccurs attributes can also be used with compositors to
repeat entire sequences of items
The Scope of an Element
Global Scope: Declarations that are placed as children of the root schema
element have a global scope, and can be referenced throughout the schema file.
Local Scope: Declarations that are nested within a complex type have a local
scope; they cannot be referenced elsewhere.
*Note:
• The attribute “use” for attributes is set locally.
• The attributes minOccurs and maxOccurs for elements are set locally.
• We declare the element or attribute globally, then specify the restrictions
locally.
XML SCHEMA DATA TYPES
• XML Schema supports two general categories of data types:
• A built-in data type is part of the XML Schema language and is
available to all XML Schema authors.
• A user-derived data type is created by a schema author for
specific data values in an instance document.
XML SCHEMA DATA TYPES
• XML Schema divides its built-in data types into two classes:
• A primitive data type, also called a base type, is one of 19 fundamental
data types not defined in terms of other types.
• A derived data type is a collection of 25 data types that the XML
Schema developers created based on the 19 primitive types.
• Unlike DTDs, schemas use the same data types for both elements and
attributes.
STRING DATA TYPES
STRING DATA TYPES
the string data types that we will use are: string , ID
NUMERIC DATA TYPES
NUMERIC DATA TYPES
DATES AND TIMES
DATES AND TIMES
the date and time data types we will use are: date , time
PATIENT.XSD USING THE “REF”
PATIENT.XSD WITHOUT USING THE “REF”
APPLYINGASCHEMATOAN XMLDOCUMENT
● To attach a schema to the document, you must do the following:
–Declare a namespace for XML Schema in the instance document.
–Indicate the location of the schema file.
● To declare the XML Schema namespace in the instance document, you add the
following attribute to the document’s root element:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
● If there is no namespace for the contents of the instance document, add the
following attribute to the root element:
xsi:noNamespaceSchemaLocation="schemaFile.xsd"
APPLYINGASCHEMATOAN XMLDOCUMENT
SUMMARY: SCHEMA ELEMENTS AND
ATTRIBUTES
Element Attribute
xs:schema xmlns:xs
xs:element name, type, minOccurs, maxOccurs, ref
xs:attribute name, type, use, default, fixed
xs:complexType mixed
xs:sequence minOccurs, maxOccurs
xs:choice minOccurs, maxOccurs
xs:all minOccurs, maxOccurs

Contenu connexe

Tendances

Tendances (20)

Xml schema
Xml schemaXml schema
Xml schema
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XSLT
XSLTXSLT
XSLT
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
Xslt
XsltXslt
Xslt
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
XSD Incomplete Overview Draft
XSD Incomplete Overview DraftXSD Incomplete Overview Draft
XSD Incomplete Overview Draft
 
XSLT. Basic.
XSLT. Basic.XSLT. Basic.
XSLT. Basic.
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
 
Xslt
XsltXslt
Xslt
 
Xml 2
Xml  2 Xml  2
Xml 2
 
Xsd tutorial
Xsd tutorialXsd tutorial
Xsd tutorial
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 

En vedette

Unleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in BatchUnleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in Batch
c7002593
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 

En vedette (20)

Xml part 6
Xml part 6Xml part 6
Xml part 6
 
Web Services
Web ServicesWeb Services
Web Services
 
The Mystical Principles of XSLT: Enlightenment through Software Visualization
The Mystical Principles of XSLT: Enlightenment through Software VisualizationThe Mystical Principles of XSLT: Enlightenment through Software Visualization
The Mystical Principles of XSLT: Enlightenment through Software Visualization
 
Unleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in BatchUnleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in Batch
 
Applying an IBM SOA Approach to Manual Processes Automation
Applying an IBM SOA Approach to Manual Processes AutomationApplying an IBM SOA Approach to Manual Processes Automation
Applying an IBM SOA Approach to Manual Processes Automation
 
XML - Displaying Data ith XSLT
XML - Displaying Data ith XSLTXML - Displaying Data ith XSLT
XML - Displaying Data ith XSLT
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
SOA Governance and WebSphere Service Registry and Repository
SOA Governance and WebSphere Service Registry and RepositorySOA Governance and WebSphere Service Registry and Repository
SOA Governance and WebSphere Service Registry and Repository
 
Open Id, O Auth And Webservices
Open Id, O Auth And WebservicesOpen Id, O Auth And Webservices
Open Id, O Auth And Webservices
 
XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
Web Services
Web ServicesWeb Services
Web Services
 
Web services
Web servicesWeb services
Web services
 
WebService-Java
WebService-JavaWebService-Java
WebService-Java
 
Siebel Web Service
Siebel Web ServiceSiebel Web Service
Siebel Web Service
 
CTDA Workshop on XSL
CTDA Workshop on XSLCTDA Workshop on XSL
CTDA Workshop on XSL
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 
XSLT
XSLTXSLT
XSLT
 
OAuth 2.0 with IBM WebSphere DataPower
OAuth 2.0 with IBM WebSphere DataPowerOAuth 2.0 with IBM WebSphere DataPower
OAuth 2.0 with IBM WebSphere DataPower
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 

Similaire à Xml part4

Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
phanleson
 

Similaire à Xml part4 (20)

02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Schemas 2 - Restricting Values
Schemas 2 - Restricting ValuesSchemas 2 - Restricting Values
Schemas 2 - Restricting Values
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Web Service Workshop - 3 days
Web Service Workshop - 3 daysWeb Service Workshop - 3 days
Web Service Workshop - 3 days
 
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Service Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML SchemaService Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML Schema
 
XML_schema_Structure
XML_schema_StructureXML_schema_Structure
XML_schema_Structure
 
XML
XMLXML
XML
 
XML, DTD & XSD Overview
XML, DTD & XSD OverviewXML, DTD & XSD Overview
XML, DTD & XSD Overview
 
XML Fundamentals
XML FundamentalsXML Fundamentals
XML Fundamentals
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Day2 xslt x_path_xquery
Day2 xslt x_path_xqueryDay2 xslt x_path_xquery
Day2 xslt x_path_xquery
 
Tool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAMLTool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAML
 
Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
Xml session
Xml sessionXml session
Xml session
 
Week 12 xml and xsl
Week 12 xml and xslWeek 12 xml and xsl
Week 12 xml and xsl
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Xml part4

  • 2. LIMITATION OF DTD • DTD has limitation on the number of data type can be used. • Can not recognize the namespace.
  • 3. SCHEMAS ● A schema is an XML document that defines the content and structure of one or more XML documents. ● The XML document that will be validated is called the instance document. ● Why Use an XML Schema? ● With XML Schema, your XML files can carry a description of its own format.
  • 5. XML SCHEMA V.S DTD • XML Schemas are More Powerful than DTD: • XML Schemas are written in XML. • XML Schema supports a collection of built-in data types and allows programmers to define their own data types. • XML Schemas support data types. • XML Schemas support namespaces.
  • 6. STARTING A SCHEMA FILE • A schema is always placed in a separate XML document that is referenced by the instance document. • A file written in XML Schema has the extension .xsd • Since the Schema file is actually an XML file, it must start with an XML declaration. • The root element in any XML Schema document is the schema element , and it must declare a namespace for the XML Schema. <?xml version=“1.0” encoding=“UTF=8”?> <xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”> schema content </xs:schema>
  • 8.
  • 9. SCHEMATYPES XML Schema recognize two categories of element types that are: 1. A complex type element has one or more attributes, or is the parent to one or more child elements. 2. A simple type element contains only character data and has no attributes.
  • 13. SIMPLE TYPE ELEMENTS • Use the following syntax to declare a simple type element in XML Schema: <xs:element name=“name” type =“xs:type”/> ● Here, name is the name of the element in the instance document and type is the datatype of the element. ● XML Schema tags must be qualified with the namespace prefix.
  • 14.
  • 15. DECLARINGANATTRIBUTE • An attribute is always a simple type. The syntax to define an attribute is <xs:attribute name="name" type="xs:type” /> • Where name is the name of the attribute and type is the data type. • You can also define a default value and a fixed value for the attribute: <xs:attribute name="name" type="xs:type” default=“default value” fixed=“fixed value" /> • The default and fixed attributes are optional.
  • 16. * notice that we did not specify which element the attribute belongs to
  • 18. COMPLEX TYPE ELEMENTS The basic structure for defining a complex type element with XML Schema is <xs:element name="name"> <xs:complexType> declarations </xs:complexType> </xs:element> Where name is the name of the element and declarations are the declarations of the child elements or attributes associated with the element.
  • 19. COMPLEX TYPE ELEMENTS Five complex type elements that usually appear in an instance document are the following: 1–The element is an empty element and contains attributes only. 2–The element contains child elements only. 3–The element contains both child elements and attributes. 4–The element contains both child elements and text. 5–The element contains both attributes and text but no child element.
  • 20. 1- ELEMENTS WITHATTRIBUTES ONLY • The code to declare an element with attributes only: <xs:element name="name"> <xs:complexType> attributes </xs:complexType> </xs:element> • Where attributes is the set of declarations that define the attributes associated with the element. For example, the empty element: <subject name="Cynthia Dibbs" age="62" /> • The code for this complex type element has the following structure: <xs:element name="subject"> <xs:complexType> <xs:attribute name="name" type="xs:string" /> <xs:attribute name="age" type="xs:string" /> </xs:complexType> </xs:element>
  • 21. SPECIFYING THE USE OFANATTRIBUTE • An attribute may or may not be required with a particular element. To indicate whether an attribute is required, you add the “use” attribute to the element declaration. The “use” attribute has the following values: • required: The attribute must always appear with the element • optional: The use of the attribute is optional with the element • prohibited: The attribute cannot be used with the element • If you neglect to add the “use” attribute to an element declaration, the parser assumes that the attribute is optional (meaning that “optional” is the default value for the “use” attribute). • Example:
  • 22. 2-ELEMENTS WITH CHILD ELEMENTS ONLY To define child elements, use the code structure: <xs:element name="name"> <xs:complexType> <xs:compositor> elements </xs:compositor> </xs:complexType> </xs:element> Where elements is the list of simple type element declarations for each child element, and compositor defines how the child elements are organized.
  • 23. USING COMPOSITORS XML Schema supports the following compositors: • sequence: defines a specific order for the child elements • choice: allows any one of the child elements to appear in the instance document • all: allows any of the child elements to appear in any order in the instance document; however, they must appear at least once.
  • 24. 2-ELEMENTS WITH CHILD ELEMENTS ONLY(SEQUANCE EXAMPLE) <element name="address"> <xs:complexType> <xs:sequence> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="country" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>
  • 25. 2-ELEMENTS WITH CHILD ELEMENTS ONLY Example for choice compositor: Example for all compositor:
  • 26. COMBINING/NESTING COMPOSITORS <xs:element name=“employee”> <xs:complexType> <xs:sequence> <xs:element name=“name” type=“xs:string”/> <xs:choice> <xs:element name=“age” type=“xs:integer”/> <xs:element name=“DOB” type=“xs:date”/> </xs:choice> <xs:all> <xs:element name=“phone” type=“xs:string”/> <xs:element name=“mobile” type=“xs:string”/> <xs:element name=“email” type=“xs:string”/> </xs:all> </xs:sequence> </xs:complexType> </xs:element>
  • 27. 3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES The code for a complex type element that contains both attributes and child elements is <xs:element name="name"> <xs:complexType> <xs:compositor> Child Elements </xs:compositor> attributes </xs:complexType> </xs:element>
  • 28. • The patient element contains two attributes (patID and onStudy) and seven child elements (lastName, firstName, dateOfBirth, age, stage, comment, and performance.) <xs:element name="patient"> <xs:complexType> <xs:sequence> <xs:element ref="lastName"/> <xs:element ref="firstName"/> <xs:element ref="dateOfBirth"/> <xs:element ref="age"/> <xs:element ref="stage"/> <xs:element ref="comment" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="performance"/> </xs:sequence> <xs:attribute ref="patID" use="required"/> <xs:attribute ref="onStudy" use="required"/> </xs:complexType> </xs:element> 3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES
  • 29. 3- ELEMENTS WITH CHILD ELEMENTSANDATTRIBUTES
  • 30. 4- SPECIFYING MIXED CONTENT • To declare an element that contains child elements and text, add the “mixed” attribute and set it to “true”. • Note that XML Schema allows content text to appear before, between, and after any of the child elements.
  • 31. For example, the XML content: <Summary> Patient <Name>Cynthia Davis</Name> was enrolled in the <Study>Tamoxifen Study</Study> on 8/15/2003. </Summary> Can be declared in the schema file using the following complex type: <xs:element name="Summary"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="Name" type=“xs:string"/> <xs:element name="Study" type=“xs:string"/> </xs:sequence> </xs:complexType> </xs:element> 4- SPECIFYING MIXED CONTENT
  • 32. 5- ELEMENTS WITH TEXTANDATTRIBUTES BUT NO CHILD ELEMENTS If an element contains text and attributes (but no child elements), the structure of the complex type element is slightly different. <xs:element name="name"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:type"> attributes </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
  • 33. For example, the empty element: <performance scale="Karnofsky"> 0.81 </performance> The code to associate the scale attribute with the performance element would therefore be <xs:element name="performance"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="scale" type="xs:string" /> </xs:extension> </xs:simpleContent> </xs:complexType> 5- ELEMENTS WITH TEXTANDATTRIBUTES BUT NO CHILD ELEMENTS
  • 34. REFERENCINGAN ELEMENT ORATTRIBUTE XML Schema allows for a great deal of flexibility in designing complex types. Rather than nesting the attribute declaration within the element, you can create a reference to it. The code to create a reference to an element or attribute declaration is <xs:element ref="elemName" /> <xs:attribute ref="attName" /> Where elemName is the name used in an element declaration and attName is the name used in an attribute declaration
  • 37. SPECIFYING THE OCCURRENCE OFAN ITEM • You can specify the occurrence of an element using the attributes minOccurs and maxOccurs. • The minOccurs and maxOccurs can be any positive value • The maxOccurs can have a value of “unbounded” for unlimited occurrences of the child element if minOccurs=”0” and maxOccurs is omitted ==> maxOccurs=”1” ==> the element is optional if minOccurs=”x” and maxOccurs is omitted ==> maxOccurs=”x” (where x is any number greater than 0) if minOccurs and maxOccurs are both omitted ==> minOccurs=”1” and maxOccurs=”1” *The default value for minOccurs and maxOccurs is “1” “+” in DTDs is : minOccurs=“1” maxOccurs=“unbound” “*” in DTDs is : minOccurs=“0” maxOccurs=“unbound” “?” in DTDs is : minOccurs=“0” maxOccurs=“1”
  • 39. SPECIFYING THE OCCURRENCE OFASEQUENCE minOccurs and maxOccurs attributes can also be used with compositors to repeat entire sequences of items
  • 40. The Scope of an Element Global Scope: Declarations that are placed as children of the root schema element have a global scope, and can be referenced throughout the schema file. Local Scope: Declarations that are nested within a complex type have a local scope; they cannot be referenced elsewhere. *Note: • The attribute “use” for attributes is set locally. • The attributes minOccurs and maxOccurs for elements are set locally. • We declare the element or attribute globally, then specify the restrictions locally.
  • 41.
  • 42. XML SCHEMA DATA TYPES • XML Schema supports two general categories of data types: • A built-in data type is part of the XML Schema language and is available to all XML Schema authors. • A user-derived data type is created by a schema author for specific data values in an instance document.
  • 43. XML SCHEMA DATA TYPES • XML Schema divides its built-in data types into two classes: • A primitive data type, also called a base type, is one of 19 fundamental data types not defined in terms of other types. • A derived data type is a collection of 25 data types that the XML Schema developers created based on the 19 primitive types. • Unlike DTDs, schemas use the same data types for both elements and attributes.
  • 44.
  • 46. STRING DATA TYPES the string data types that we will use are: string , ID
  • 50. DATES AND TIMES the date and time data types we will use are: date , time
  • 52. PATIENT.XSD WITHOUT USING THE “REF”
  • 53. APPLYINGASCHEMATOAN XMLDOCUMENT ● To attach a schema to the document, you must do the following: –Declare a namespace for XML Schema in the instance document. –Indicate the location of the schema file. ● To declare the XML Schema namespace in the instance document, you add the following attribute to the document’s root element: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ● If there is no namespace for the contents of the instance document, add the following attribute to the root element: xsi:noNamespaceSchemaLocation="schemaFile.xsd"
  • 55. SUMMARY: SCHEMA ELEMENTS AND ATTRIBUTES Element Attribute xs:schema xmlns:xs xs:element name, type, minOccurs, maxOccurs, ref xs:attribute name, type, use, default, fixed xs:complexType mixed xs:sequence minOccurs, maxOccurs xs:choice minOccurs, maxOccurs xs:all minOccurs, maxOccurs