Академический Документы
Профессиональный Документы
Культура Документы
Lecture 4
XSD (XML Schema Definition)
PART 1
Agenda
XML Validation
XML Namespaces
XML Schema Definition
XML Schema Data Types
XML Schema Elements
SimpleType
ComplexType
Schema Element Declaration
2
Recap: Well-formed XML
Syntax Rules:
XML Documents Must Have a Root Element.
All XML Elements Must Have a Closing Tag.
XML Tags are Case Sensitive.
XML Elements Must be Properly Nested.
XML Attribute Values Must be Quoted.
Naming Rules:
Element names are case-sensitive.
Element names must start with a letter or underscore.
Element names cannot start with the letters xml (or XML, or
Xml, etc).
Element names can contain letters, digits, hyphens,
underscores, and periods.
Element names cannot contain spaces.
3
XML Namespaces
Before considering XML Schemas and
Validation, it is important to know the use of
XML Namespaces.
There will be no
conflict because the
two <table> elements
have different
names.
XML Namespaces
The xmlns Attribute
When using prefixes in XML, a namespace for the
prefix must be defined.
The namespace can be defined by an xmlns attribute
in the start tag of an element.
Namespaces can also be declared in the XML root
element.
10
Namespace declaration
An XML Namespace is declared using the
reserved XML attribute xmlns:prefix or xmlns, the
value of which must be a valid namespace name.
Examples:
xmlns:xhtml=http://www.w3.org/1999/xhtml
Any element or attribute whose name starts with the prefix
"xhtml:" is considered to be in the XHTML namespace
xmlns=http://www.w3.org/1999/xhtml
It is also possible to declare a default namespace. Any
element without a namespace prefix is considered to be in
the XHTML namespace.
11
Namespace Example
(Declaration in the XML root element)
12
XML Schema
XML schema describes the structure of an XML
instance document by defining what each
element must or may contain.
13
14
XML Schema Example (1)
Email.xsd
http://www.w3.org/2001/XMLSchema
17
https://dhhmzgirqh63s.cloudfront.net/27930.gif 19
20
Simple Type Element
Simple type element contains only text.
Example:
<Subject>Web Application Development</Subject>
21
Activity 1
Write the schema definitions for the following
XML elements:
<lastName>Smith</lastName>
<age>35</age>
<dateofBirth>1985-05-17</dateofBirth>
23
25
27
Activity 2
Write the schema definition for the following
XML file:
<?xml version="1.0" encoding="UTF-8"?>
<person>
<lastName>Smith</lastName>
<age>35</age>
<dateofBirth>1985-05-17</dateofBirth>
</person>
Refer to Activity 1
28
Complex Type Element
(Mixed Content)
A mixed complex type element can contain
attributes, elements, and text.
31
References
https://www.w3schools.com/xml/
https://www.w3schools.com/xml/xml_namespac
es.asp
https://www.w3schools.com/xml/schema_intro.a
sp
https://www.webucator.com/tutorial/learn-xml-
schema/xml-schema-basics/a-first-look-
reading.cfm
https://www.w3schools.com/xml/schema_compl
ex_mixed.asp
32