SlideShare a Scribd company logo
INTRODUCTION TO XML
Tatyana Kosova
May 30, 2013 www.ExigenServices.com
2 www.ExigenServices.com
• WHAT IS XML
• XML SYNTAX
• XML TAGS
• XML ELEMENTS
• XML ATTRIBUTES
• XML SCHEME
• XML TOOLS
3 www.ExigenServices.com
XML
• Is a standart for EXtensible Markup Language
• Is a markup language much like HTML
• XML was designed to describe data
• XML tags are not predefined. You must define your own tags
• XML uses a Document Type Definition (DTD) or an
XML Schema to describe the data
4 www.ExigenServices.com
IMPORTANT TO KNOW!
XML doesn’t
DO anything!
Just structure,
store and send
information.
5 www.ExigenServices.com
XML SYNTAX
• XML declaration (standart and encoding)
• Can be comment (is inserted in tags <!-- comment -->)
• Element
• Child elements
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--DOCTYPE note SYSTEM "InternalNote.dtd“-->
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML Example:
6 www.ExigenServices.com
XML TAGS
• All XML documents must have closing a tag
<element> this is an element </element>
<element1>this is another element </element1>
• XML tags are case sensitive
<!– correct -->
<element> this is an element </element>
<!– wrong -->
<element1>this is another element </Element1>
• All XML documents must be properly nested
<!– correct -->
<b><i> this text is bold and italic </i></b>
<!– wrong -->
<b><i> this text is bold and italic </b></i>
7 www.ExigenServices.com
XML ELEMENTS
• XML elements are related as parents and children
<root>
<child>
<subchild>….</subchild>
</child>
</root>
8 www.ExigenServices.com
XML ELEMENTS NAMING
• XML elements have the different content type
<book>
<title>BOOK TITLE</title>
<prod id="33-657"
media="paper"></prod>
<chapter>CHAPTER ONE
<para>paragraph 1</para>
<para>paragraph 2</para>
</chapter>
<chapter>CHAPTER TWO
<para>paragraph 1</para>
</chapter>
</book>
9 www.ExigenServices.com
XML ATTRIBUTES
• Attribute values must always be enclosed in quotes
<person sex="female">
• If the attribute value itself contains double quotes it is necessary
to use single quotes
or <person sex=‘female’>
<gangster name='George "Shotgun" Ziegler'>
• If the attribute value itself contains single quotes it is necessary
to use double quotes
<gangster name=“George ‘Shotgun’ Ziegler”>
10 www.ExigenServices.com
XML ATTRIBUTES
• The following example defines an element called "age" with a restriction.
The value of age cannot be lower than 0 or greater than 120:
<xs:element name="age">
< xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
< /xs:simpleType>
< /xs:element>
11 www.ExigenServices.com
DTD SCHEME
• Attribute’s type and property
<!ATTLIST message
number CDATA #REQUIRED
date CDATA #REQUIRED
from CDATA #FIXED
status CDATA #IMPLIED>
• Elements and attributes should be described in DTD in order they used in
XML
• DTD can be defined in XML in second line
<?xml version="1.0" ?>
<!DOCTYPE mailbox SYSTEM "mailbox.dtd">
12 www.ExigenServices.com
DTD EXAMPLE
<!ELEMENT mailbox (message*)>
<!ELEMENT message (head, body)>
<!ATTLIST message uid CDATA #REQUIRED>
<!ELEMENT head ( from,to+, subject?, CC*,
notify?) >
<!ELEMENT from (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT subject (#PCDATA)>
<!ELEMENT CC (#PCDATA)>
<!ELEMENT notify EMPTY>
<!ELEMENT body (#PCDATA)>
<?xml version="1.0" ?>
<!DOCTYPE mailbox SYSTEM
"mailbox.dtd">
<mailbox>
<message uid="1">
<head>
<from>user1@myhp.edu</from>
<to>user2@myhp.edu</to>
<subject>Re:</subject>
</head>
<body> What's up! </body>
</message>
<message uid="2">
…
</message>
</mailbox>
DTD XML
13 www.ExigenServices.com
XSD EXAMPLE
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLScheme
">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading"
type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0"?>
<xs:schema
xmlns:xs="http://www.w3.org/20
01/XMLScheme">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Hello!</body>
</note>
XMLXML SCHEME
14 www.ExigenServices.com
XML tools
• XML on-line validators
http://www.w3schools.com/dom/dom_validate.asp
• XML validators
XML ValidatorBuddy
• XML tools:
• Stylus Studio
• XML Notepad
• XML Copy Editor
• Exchanger XML Lite
• XMLPad
• XML Spy
15 www.ExigenServices.com
RESOLUTION
• XML was designed to carry data.
• XML has it’s own syntax
• XML should has a scheme
• XML document contains elements and attributes
• XML document has tags
• XML document is easy to create and validate
16 www.ExigenServices.com
<?xml version="1.0" encoding="WINDOWS-1251"?>
<?xml-stylesheet type='text/xsl' href='ex01-1.xsl'?>
<tutorial>
<title>“Introduction to XML"</title>
<author>Bob Hitch</author>
</toturial>
WRONG OR CORRECT
17 www.ExigenServices.com
QUESTIONS?

More Related Content

PPTX
PDF
Cmsc 100 xhtml and css
PPTX
FFW Gabrovo PMG - jQuery
PPTX
FFW Gabrovo PMG - JavaScript 1
PPTX
Css Selectors
PPTX
Css selector - BNT 11
PDF
XSD Incomplete Overview Draft
PPTX
Html dom & j query
Cmsc 100 xhtml and css
FFW Gabrovo PMG - jQuery
FFW Gabrovo PMG - JavaScript 1
Css Selectors
Css selector - BNT 11
XSD Incomplete Overview Draft
Html dom & j query

What's hot (20)

PDF
Interacting with the DOM (JavaScript)
PPTX
Javascript inside Browser (DOM)
PPTX
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
PPTX
Selenium Locators
PPTX
FFW Gabrovo PMG - HTML
PPTX
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
PPTX
Efficient use of jQuery selector
PPT
Xml dom & sax by bhavsingh maloth
PPT
Intro to jQuery
PPTX
CSS101 - Concept Fundamentals for non UI Developers
PPTX
Internet and Web Technology (CLASS-6) [BOM]
PDF
CSS- Smacss Design Rule
PDF
LF_APIStrat17_Embracing JSON Schema
PDF
Create an Design JSON Schema
PPT
Java Script Basics
PDF
JSON Schema Design
PPTX
Web Development Basics: HOW TO in HTML
PDF
Unit 4(it workshop)
PDF
Objects, Objects Everywhere
Interacting with the DOM (JavaScript)
Javascript inside Browser (DOM)
Internet and Web Technology (CLASS-9) [React.js] | NIC/NIELIT Web Technology
Selenium Locators
FFW Gabrovo PMG - HTML
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Efficient use of jQuery selector
Xml dom & sax by bhavsingh maloth
Intro to jQuery
CSS101 - Concept Fundamentals for non UI Developers
Internet and Web Technology (CLASS-6) [BOM]
CSS- Smacss Design Rule
LF_APIStrat17_Embracing JSON Schema
Create an Design JSON Schema
Java Script Basics
JSON Schema Design
Web Development Basics: HOW TO in HTML
Unit 4(it workshop)
Objects, Objects Everywhere
Ad

Viewers also liked (20)

PPTX
XML's validation - DTD
PPT
Xml Schema
PPTX
How to develop your creativity
PPT
Quality Principles
PPTX
Non Blocking Algorithms at Traffic Conditions
PPT
English for E-mails
PPTX
Profsoux2014 presentation by Pavelchuk
PPT
Successful interview for a young IT specialist
PPTX
Windows Azure: Quick start
PDF
Apache Maven presentation from BitByte conference
PPTX
Introduction to python
PPTX
Time Management
PPTX
Apache Maven 2 Part 2
PPTX
Agile Project Grows
PPTX
Large Scale Software Project
PPT
Jira as a test management tool
PPTX
Service design principles and patterns
PPTX
Risk Management
PPTX
Principles of personal effectiveness
PPTX
Cross-cultural communication
XML's validation - DTD
Xml Schema
How to develop your creativity
Quality Principles
Non Blocking Algorithms at Traffic Conditions
English for E-mails
Profsoux2014 presentation by Pavelchuk
Successful interview for a young IT specialist
Windows Azure: Quick start
Apache Maven presentation from BitByte conference
Introduction to python
Time Management
Apache Maven 2 Part 2
Agile Project Grows
Large Scale Software Project
Jira as a test management tool
Service design principles and patterns
Risk Management
Principles of personal effectiveness
Cross-cultural communication
Ad

Similar to Introduction to XML (20)

PDF
II UNIT PPT NOTES.pdf this is the data structures
PPT
02 xml schema
PDF
Web Technologies Unit 2 Print.pdf
PPTX
XML Schema
PPTX
XML, DTD & XSD Overview
PPTX
distributed system concerned lab sessions
PPTX
It8074 soa-unit i
PPT
Intro to xml
PPTX
xml.pptx
PPT
Ch2 neworder
PPTX
Unit iv xml
PPT
Data mining lecture 3 taught at Stanford
PDF
WT UNIT-2 XML.pdf
PPT
Xml and DTD's
PDF
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
PPTX
PDF
Xml
PPT
Xsd examples
PPT
Chen's first test slides
II UNIT PPT NOTES.pdf this is the data structures
02 xml schema
Web Technologies Unit 2 Print.pdf
XML Schema
XML, DTD & XSD Overview
distributed system concerned lab sessions
It8074 soa-unit i
Intro to xml
xml.pptx
Ch2 neworder
Unit iv xml
Data mining lecture 3 taught at Stanford
WT UNIT-2 XML.pdf
Xml and DTD's
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Xml
Xsd examples
Chen's first test slides

More from Return on Intelligence (15)

PPTX
Types of testing and their classification
PPTX
Differences between Testing in Waterfall and Agile
PPTX
Windows azurequickstart
PPT
Организация внутренней системы обучения
PPTX
Shared position in a project: testing and analysis
PPTX
Introduction to Business Etiquette
PPTX
Agile Testing Process
PPTX
Оценка задач выполняемых по итеративной разработке
PPTX
Meetings arranging
PPTX
The art of project estimation
PPT
Resolving conflicts
PPTX
Velocity как инструмент планирования и управления проектом
PPTX
Testing your code
PPTX
Reports Project
PPTX
Business Analyst lecture
Types of testing and their classification
Differences between Testing in Waterfall and Agile
Windows azurequickstart
Организация внутренней системы обучения
Shared position in a project: testing and analysis
Introduction to Business Etiquette
Agile Testing Process
Оценка задач выполняемых по итеративной разработке
Meetings arranging
The art of project estimation
Resolving conflicts
Velocity как инструмент планирования и управления проектом
Testing your code
Reports Project
Business Analyst lecture

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
A Presentation on Artificial Intelligence
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Diabetes mellitus diagnosis method based random forest with bat algorithm
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
A Presentation on Artificial Intelligence

Introduction to XML

  • 1. INTRODUCTION TO XML Tatyana Kosova May 30, 2013 www.ExigenServices.com
  • 2. 2 www.ExigenServices.com • WHAT IS XML • XML SYNTAX • XML TAGS • XML ELEMENTS • XML ATTRIBUTES • XML SCHEME • XML TOOLS
  • 3. 3 www.ExigenServices.com XML • Is a standart for EXtensible Markup Language • Is a markup language much like HTML • XML was designed to describe data • XML tags are not predefined. You must define your own tags • XML uses a Document Type Definition (DTD) or an XML Schema to describe the data
  • 4. 4 www.ExigenServices.com IMPORTANT TO KNOW! XML doesn’t DO anything! Just structure, store and send information.
  • 5. 5 www.ExigenServices.com XML SYNTAX • XML declaration (standart and encoding) • Can be comment (is inserted in tags <!-- comment -->) • Element • Child elements <?xml version="1.0" encoding="ISO-8859-1"?> <!--DOCTYPE note SYSTEM "InternalNote.dtd“--> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XML Example:
  • 6. 6 www.ExigenServices.com XML TAGS • All XML documents must have closing a tag <element> this is an element </element> <element1>this is another element </element1> • XML tags are case sensitive <!– correct --> <element> this is an element </element> <!– wrong --> <element1>this is another element </Element1> • All XML documents must be properly nested <!– correct --> <b><i> this text is bold and italic </i></b> <!– wrong --> <b><i> this text is bold and italic </b></i>
  • 7. 7 www.ExigenServices.com XML ELEMENTS • XML elements are related as parents and children <root> <child> <subchild>….</subchild> </child> </root>
  • 8. 8 www.ExigenServices.com XML ELEMENTS NAMING • XML elements have the different content type <book> <title>BOOK TITLE</title> <prod id="33-657" media="paper"></prod> <chapter>CHAPTER ONE <para>paragraph 1</para> <para>paragraph 2</para> </chapter> <chapter>CHAPTER TWO <para>paragraph 1</para> </chapter> </book>
  • 9. 9 www.ExigenServices.com XML ATTRIBUTES • Attribute values must always be enclosed in quotes <person sex="female"> • If the attribute value itself contains double quotes it is necessary to use single quotes or <person sex=‘female’> <gangster name='George "Shotgun" Ziegler'> • If the attribute value itself contains single quotes it is necessary to use double quotes <gangster name=“George ‘Shotgun’ Ziegler”>
  • 10. 10 www.ExigenServices.com XML ATTRIBUTES • The following example defines an element called "age" with a restriction. The value of age cannot be lower than 0 or greater than 120: <xs:element name="age"> < xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="120"/> </xs:restriction> < /xs:simpleType> < /xs:element>
  • 11. 11 www.ExigenServices.com DTD SCHEME • Attribute’s type and property <!ATTLIST message number CDATA #REQUIRED date CDATA #REQUIRED from CDATA #FIXED status CDATA #IMPLIED> • Elements and attributes should be described in DTD in order they used in XML • DTD can be defined in XML in second line <?xml version="1.0" ?> <!DOCTYPE mailbox SYSTEM "mailbox.dtd">
  • 12. 12 www.ExigenServices.com DTD EXAMPLE <!ELEMENT mailbox (message*)> <!ELEMENT message (head, body)> <!ATTLIST message uid CDATA #REQUIRED> <!ELEMENT head ( from,to+, subject?, CC*, notify?) > <!ELEMENT from (#PCDATA)> <!ELEMENT to (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT CC (#PCDATA)> <!ELEMENT notify EMPTY> <!ELEMENT body (#PCDATA)> <?xml version="1.0" ?> <!DOCTYPE mailbox SYSTEM "mailbox.dtd"> <mailbox> <message uid="1"> <head> <from>user1@myhp.edu</from> <to>user2@myhp.edu</to> <subject>Re:</subject> </head> <body> What's up! </body> </message> <message uid="2"> … </message> </mailbox> DTD XML
  • 13. 13 www.ExigenServices.com XSD EXAMPLE <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLScheme "> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/20 01/XMLScheme"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Hello!</body> </note> XMLXML SCHEME
  • 14. 14 www.ExigenServices.com XML tools • XML on-line validators http://www.w3schools.com/dom/dom_validate.asp • XML validators XML ValidatorBuddy • XML tools: • Stylus Studio • XML Notepad • XML Copy Editor • Exchanger XML Lite • XMLPad • XML Spy
  • 15. 15 www.ExigenServices.com RESOLUTION • XML was designed to carry data. • XML has it’s own syntax • XML should has a scheme • XML document contains elements and attributes • XML document has tags • XML document is easy to create and validate
  • 16. 16 www.ExigenServices.com <?xml version="1.0" encoding="WINDOWS-1251"?> <?xml-stylesheet type='text/xsl' href='ex01-1.xsl'?> <tutorial> <title>“Introduction to XML"</title> <author>Bob Hitch</author> </toturial> WRONG OR CORRECT

Editor's Notes

  • #6: &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?&gt; will give an error message
  • #8: Elements can be simple and complex. Simple element is an XML element that can contain only text. It cannot contain any other elements or attributes. However, the &quot;only text&quot; restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself. You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern. The syntax for defining a simple element is: &lt; xs:element name=&quot;xxx&quot; type=&quot;yyy&quot;/&gt; where xxx is the name of the element and yyy is the data type of the element. XML Schema has a lot of built-in data types. The most common types are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time Example Here are some XML elements: &lt; lastname&gt;Refsnes&lt;/lastname&gt; &lt; age&gt;36&lt;/age&gt; &lt; dateborn&gt;1970-03-27&lt;/dateborn&gt; And here are the corresponding simple element definitions: &lt; xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt; xs:element name=&quot;age&quot; type=&quot;xs:integer&quot;/&gt; &lt; xs:element name=&quot;dateborn&quot; type=&quot;xs:date&quot;/&gt; Simple elements may have a default value OR a fixed value specified. A default value is automatically assigned to the element when no other value is specified. In the following example the default value is &quot;red&quot;: &lt; xs:element name=&quot;color&quot; type=&quot;xs:string&quot; default=&quot;red&quot;/&gt; A fixed value is also automatically assigned to the element, and you cannot specify another value. In the following example the fixed value is &quot;red&quot;: &lt; xs:element name=&quot;color&quot; type=&quot;xs:string&quot; fixed=&quot;red&quot;/&gt; A complex element is an XML element that contains other elements and/or attributes. There are four kinds of complex elements: empty elements elements that contain only other elements elements that contain only text elements that contain both other elements and text Examples of Complex Elements A complex XML element, &quot;product&quot;, which is empty: &lt; product pid=&quot;1345&quot;/&gt; A complex XML element, &quot;employee&quot;, which contains only other elements: &lt; employee&gt; &lt; firstname&gt;John&lt;/firstname&gt; &lt; lastname&gt;Smith&lt;/lastname&gt; &lt; /employee&gt; A complex XML element, &quot;food&quot;, which contains only text: &lt; food type=&quot;dessert&quot;&gt;Ice cream&lt;/food&gt; A complex XML element, &quot;description&quot;, which contains both elements and text: &lt; description&gt; It happened on &lt;date lang=&quot;norwegian&quot;&gt;03.03.99&lt;/date&gt; .... &lt; /description&gt; How to Define a Complex Element Look at this complex XML element, &quot;employee&quot;, which contains only other elements: &lt; employee&gt; &lt; firstname&gt;John&lt;/firstname&gt; &lt; lastname&gt;Smith&lt;/lastname&gt; &lt; /employee&gt; We can define a complex element in an XML Schema two different ways: 1. The &quot;employee&quot; element can be declared directly by naming the element, like this: &lt; xs:element name=&quot;employee&quot;&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; If you use the method described above, only the &quot;employee&quot; element can use the specified complex type. Note that the child elements, &quot;firstname&quot; and &quot;lastname&quot;, are surrounded by the &lt;sequence&gt; indicator. This means that the child elements must appear in the same order as they are declared. You will learn more about indicators in the XSD Indicators chapter. 2. The &quot;employee&quot; element can have a type attribute that refers to the name of the complex type to use: &lt; xs:element name=&quot;employee&quot; type=&quot;personinfo&quot;/&gt; &lt; xs:complexType name=&quot;personinfo&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt; /xs:complexType&gt; If you use the method described above, several elements can refer to the same complex type, like this: &lt; xs:element name=&quot;employee&quot; type=&quot;personinfo&quot;/&gt; &lt; xs:element name=&quot;student&quot; type=&quot;personinfo&quot;/&gt; &lt; xs:element name=&quot;member&quot; type=&quot;personinfo&quot;/&gt; &lt; xs:complexType name=&quot;personinfo&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt; /xs:complexType&gt; You can also base a complex element on an existing complex element and add some elements, like this: &lt; xs:element name=&quot;employee&quot; type=&quot;fullpersoninfo&quot;/&gt; &lt; xs:complexType name=&quot;personinfo&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt; /xs:complexType&gt; &lt; xs:complexType name=&quot;fullpersoninfo&quot;&gt; &lt;xs:complexContent&gt; &lt;xs:extension base=&quot;personinfo&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;address&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;city&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;country&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt; /xs:complexType&gt; Complex Types Containing Elements Only An XML element, &quot;person&quot;, that contains only other elements: &lt; person&gt; &lt; firstname&gt;John&lt;/firstname&gt; &lt; lastname&gt;Smith&lt;/lastname&gt; &lt; /person&gt; You can define the &quot;person&quot; element in a schema, like this: &lt; xs:element name=&quot;person&quot;&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; Notice the &lt;xs:sequence&gt; tag. It means that the elements defined (&quot;firstname&quot; and &quot;lastname&quot;) must appear in that order inside a &quot;person&quot; element. Or you can give the complexType element a name, and let the &quot;person&quot; element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type): &lt; xs:element name=&quot;person&quot; type=&quot;persontype&quot;/&gt; &lt; xs:complexType name=&quot;persontype&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt; /xs:complexType&gt; Complex Types with Mixed Content An XML element, &quot;letter&quot;, that contains both text and other elements: &lt; letter&gt; Dear Mr.&lt;name&gt;John Smith&lt;/name&gt;. Your order &lt;orderid&gt;1032&lt;/orderid&gt; will be shipped on &lt;shipdate&gt;2001-07-13&lt;/shipdate&gt;. &lt; /letter&gt; The following schema declares the &quot;letter&quot; element: &lt; xs:element name=&quot;letter&quot;&gt; &lt;xs:complexType mixed=&quot;true&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;orderid&quot; type=&quot;xs:positiveInteger&quot;/&gt; &lt;xs:element name=&quot;shipdate&quot; type=&quot;xs:date&quot;/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; Note: To enable character data to appear between the child-elements of &quot;letter&quot;, the mixed attribute must be set to &quot;true&quot;. The &lt;xs:sequence&gt; tag means that the elements defined (name, orderid and shipdate) must appear in that order inside a &quot;letter&quot; element. We could also give the complexType element a name, and let the &quot;letter&quot; element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type): &lt; xs:element name=&quot;letter&quot; type=&quot;lettertype&quot;/&gt; &lt; xs:complexType name=&quot;lettertype&quot; mixed=&quot;true&quot;&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;orderid&quot; type=&quot;xs:positiveInteger&quot;/&gt; &lt;xs:element name=&quot;shipdate&quot; type=&quot;xs:date&quot;/&gt; &lt;/xs:sequence&gt; &lt; /xs:complexType&gt;
  • #9: XML elements can have different content type: element content, mixed content, Simple content or empty content or element can have attribute. Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type. Element “title” has content type, element “prod” doesn’t have any type but has an attribute. Element “chapter” has content and mixed type. Element “para” has content type. Element “book” and “chapter”ia a parent element and has child elements. The attribute named id has the value &quot;33-657&quot;. The attribute named media has the value &quot;paper&quot;.
  • #10: Example Here is an XML element with an attribute: &lt; lastname lang=&quot;EN&quot;&gt;Smith&lt;/lastname&gt; And here is the corresponding attribute definition: &lt; xs:attribute name=&quot;lang&quot; type=&quot;xs:string&quot;/&gt; Default and Fixed Values for Attributes Attributes may have a default value OR a fixed value specified. A default value is automatically assigned to the attribute when no other value is specified. In the following example the default value is &quot;EN&quot;: &lt; xs:attribute name=&quot;lang&quot; type=&quot;xs:string&quot; default=&quot;EN&quot;/&gt; A fixed value is also automatically assigned to the attribute, and you cannot specify another value. In the following example the fixed value is &quot;EN&quot;: &lt; xs:attribute name=&quot;lang&quot; type=&quot;xs:string&quot; fixed=&quot;EN&quot;/&gt; Optional and Required Attributes Attributes are optional by default. To specify that the attribute is required, use the &quot;use&quot; attribute: &lt; xs:attribute name=&quot;lang&quot; type=&quot;xs:string&quot; use=&quot;required&quot;/&gt; Restrictions on Content When an XML element or attribute has a data type defined, it puts restrictions on the element&apos;s or attribute&apos;s content. If an XML element is of type &quot;xs:date&quot; and contains a string like &quot;Hello World&quot;, the element will not validate. With XML Schemas, you can also add your own restrictions to your XML elements and attributes. These restrictions are called facets. You can read more about facets in the next chapter.
  • #11: To limit the content of an XML element to a set of acceptable values, we would use the enumeration constraint. The example below defines an element called &quot;car&quot; with a restriction. The only acceptable values are: Audi, Golf, BMW: &lt; xs:element name=&quot;car&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:enumeration value=&quot;Audi&quot;/&gt; &lt;xs:enumeration value=&quot;Golf&quot;/&gt; &lt;xs:enumeration value=&quot;BMW&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt; /xs:element&gt; The example above could also have been written like this: &lt; xs:element name=&quot;car&quot; type=&quot;carType&quot;/&gt; &lt; xs:simpleType name=&quot;carType&quot;&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:enumeration value=&quot;Audi&quot;/&gt; &lt;xs:enumeration value=&quot;Golf&quot;/&gt; &lt;xs:enumeration value=&quot;BMW&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; Note: In this case the type &quot;carType&quot; can be used by other elements because it is not a part of the &quot;car&quot; element. To limit the content of an XML element to define a series of numbers or letters that can be used, we would use the pattern constraint. The example below defines an element called &quot;letter&quot; with a restriction. The only acceptable value is ONE of the LOWERCASE letters from a to z: &lt; xs:element name=&quot;letter&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;[a-z]&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example defines an element called &quot;initials&quot; with a restriction. The only acceptable value is THREE of the UPPERCASE letters from a to z: &lt; xs:element name=&quot;initials&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;[A-Z][A-Z][A-Z]&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example also defines an element called &quot;initials&quot; with a restriction. The only acceptable value is THREE of the LOWERCASE OR UPPERCASE letters from a to z: &lt; xs:element name=&quot;initials&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;[a-zA-Z][a-zA-Z][a-zA-Z]&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example defines an element called &quot;choice&quot; with a restriction. The only acceptable value is ONE of the following letters: x, y, OR z: &lt; xs:element name=&quot;choice&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;[xyz]&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example defines an element called &quot;prodid&quot; with a restriction. The only acceptable value is FIVE digits in a sequence, and each digit must be in a range from 0 to 9: &lt; xs:element name=&quot;prodid&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:integer&quot;&gt; &lt;xs:pattern value=&quot;[0-9][0-9][0-9][0-9][0-9]&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; Other Restrictions on a Series of Values The example below defines an element called &quot;letter&quot; with a restriction. The acceptable value is zero or more occurrences of lowercase letters from a to z: &lt; xs:element name=&quot;letter&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;([a-z])*&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example also defines an element called &quot;letter&quot; with a restriction. The acceptable value is one or more pairs of letters, each pair consisting of a lower case letter followed by an upper case letter. For example, &quot;sToP&quot; will be validated by this pattern, but not &quot;Stop&quot; or &quot;STOP&quot; or &quot;stop&quot;: &lt; xs:element name=&quot;letter&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;([a-z][A-Z])+&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example defines an element called &quot;gender&quot; with a restriction. The only acceptable value is male OR female: &lt; xs:element name=&quot;gender&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;male|female&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt; The next example defines an element called &quot;password&quot; with a restriction. There must be exactly eight characters in a row and those characters must be lowercase or uppercase letters from a to z, or a number from 0 to 9: &lt; xs:element name=&quot;password&quot;&gt; &lt; xs:simpleType&gt; &lt;xs:restriction base=&quot;xs:string&quot;&gt; &lt;xs:pattern value=&quot;[a-zA-Z0-9]{8}&quot;/&gt; &lt;/xs:restriction&gt; &lt; /xs:simpleType&gt; &lt;/xs:element&gt;
  • #12: The DTD describes a scheme for a particular document markup language using a set of declarations (objects, options, elements and attributes) that describe its class (or type) in terms of syntactic constraints of this document. DTD may also declare constructs that are always needed to determine the structure of the document, but, but may influence the interpretation of certain documents. The attribute named id has the value &quot;33-657&quot;. The attribute named media has the value &quot;paper&quot;. REQUIRED – attribute should be identified. FIXED - attribute should be fixed. IMPLIED - attribute can be unengaging. There are some default properties: 1.IMPLIED - attribute is optional; 2.REQUIRED - the attribute value must be indicated; 3.FIXED - the value of this attribute is specified as a constant in the DTD and the document can not be changed; 4.nekotoroe specific value, which is used by default.
  • #13: The attribute named id has the value &quot;33-657&quot;. The attribute named media has the value &quot;paper&quot;. Declare elements form a list of authorized names of elements in the document and determine the information on the tags (if they are mandatory) and the content model for each element. Different keys words and symbols define the contents of: EMPTY - empty the contents of ANY - any content - Specifies the order | - Separation of alternatives () - Grouping * - Any number of items (zero or more) + - At least one element (one or more) ? - Availability of an optional element (zero or one) If there is no, * +, or? - The item should be only one There are some types of attributes: CDATA (Character set of data) - the attribute value can be any character data ID - the attribute value must be a unique identifier for the element IDREF - the element value is a reference to an element by its ID IDREFS - Same as IDREF, but with the possibility of links is not one identifier, and for several NMTOKEN - an attribute value can be a sequence of characters, in some ways similar to the name (hence the name - name token). This is a string that contains any combination of those characters that are allowed to use names for XML. NMTOKENS - the attribute value is a list of values ENTITY - the value used to refer to an external entity. ENTITIES - allows you to specify a list of external entities, separated by spaces. NOTATION - the attribute value can be one of the previously defined notations NOTATIONS - allows you to specify a list of notations. Listings and NOTATION-listings ENUMERATION - sets a list of possible alternative values. There are some default properties: 1.IMPLIED - attribute is optional; 2.REQUIRED - the attribute value must be indicated; 3.FIXED - the value of this attribute is specified as a constant in the DTD and the document can not be changed; 4.nekotoroe specific value, which is used by default.
  • #14: What is an XML Schema? The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema: defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes XML Schemas are the Successors of DTDs We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: XML Schemas are extensible to future additions XML Schemas are richer and more powerful than DTDs XML Schemas are written in XML XML Schemas support data types XML Schemas support namespaces XML Schema is a W3C Recommendation XML Schema became a W3C Recommendation 02. May 2001. You can read more about the XML Schema standard in our W3C tutorial . We believe that very soon XML-schema to be used in Web-based applications instead of the DTD-tables, and here&apos;s why: XML-schemas easier to learn than DTD XML-schema can be expanded in the future if needed to add some XML-Schema is richer and more useful than DTD XML-schema written in XML XML-Schema data typing support XML-schema namespace support &lt;xs:element name=&quot;to&quot; type=&quot;xs:string&quot;/&gt; - is a simple element &lt;xs:element name=&quot;note&quot;&gt; - is a complex element XML Schema has a lot of built-in data types. The most common types are: xs:string xs:decimal xs:integer xs:boolean xs:date xs:time Order indicators are used to define the order of the elements. All Indicator The &lt;all&gt; indicator specifies that the child elements can appear in any order, and that each child element must occur only once: &lt; xs:element name=&quot;person&quot;&gt; &lt;xs:complexType&gt; &lt;xs:all&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; Note: When using the &lt;all&gt; indicator you can set the &lt;minOccurs&gt; indicator to 0 or 1 and the &lt;maxOccurs&gt; indicator can only be set to 1 (the &lt;minOccurs&gt; and &lt;maxOccurs&gt; are described later). Choice Indicator The &lt;choice&gt; indicator specifies that either one child element or another can occur: &lt; xs:element name=&quot;person&quot;&gt; &lt;xs:complexType&gt; &lt;xs:choice&gt; &lt;xs:element name=&quot;employee&quot; type=&quot;employee&quot;/&gt; &lt;xs:element name=&quot;member&quot; type=&quot;member&quot;/&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; Sequence Indicator The &lt;sequence&gt; indicator specifies that the child elements must appear in a specific order: &lt; xs:element name=&quot;person&quot;&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name=&quot;firstname&quot; type=&quot;xs:string&quot;/&gt; &lt;xs:element name=&quot;lastname&quot; type=&quot;xs:string&quot;/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt; /xs:element&gt; XML Schemas Support Data Types One of the greatest strength of XML Schemas is the support for data types. With support for data types: It is easier to describe allowable document content It is easier to validate the correctness of data It is easier to work with data from a database It is easier to define data facets (restrictions on data) It is easier to define data patterns (data formats) It is easier to convert data between different data types XML Schemas use XML Syntax Another great strength about XML Schemas is that they are written in XML. Some benefits of that XML Schemas are written in XML: You don&apos;t have to learn a new language You can use your XML editor to edit your Schema files You can use your XML parser to parse your Schema files You can manipulate your Schema with the XML DOM You can transform your Schema with XSLT XML Schemas Secure Data Communication When sending data from a sender to a receiver, it is essential that both parts have the same &quot;expectations&quot; about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand. A date like: &quot;03-11-2004&quot; will, in some countries, be interpreted as 3.November and in other countries as 11.March. However, an XML element with a data type like this: &lt;date type=&quot;date&quot;&gt;2004-03-11&lt;/date&gt; ensures a mutual understanding of the content, because the XML data type &quot;date&quot; requires the format &quot;YYYY-MM-DD&quot;. XML Schemas are Extensible XML Schemas are extensible, because they are written in XML. With an extensible Schema definition you can: Reuse your Schema in other Schemas Create your own data types derived from the standard types Reference multiple schemas in the same document Well-Formed is not Enough A well-formed XML document is a document that conforms to the XML syntax rules, like: it must begin with the XML declaration it must have one unique root element start-tags must have matching end-tags elements are case sensitive all elements must be closed all elements must be properly nested all attribute values must be quoted entities must be used for special characters Even if documents are well-formed they can still contain errors, and those errors can have serious consequences. Think of the following situation: you order 5 gross of laser printers, instead of 5 laser printers. With XML Schemas, most of these errors can be caught by your validating software.
  • #15: XML is Text-based XML is a text-based markup language. One great thing about XML is that XML files can be created and edited using a simple text-editor like Notepad. However, when you start working with XML, you will soon find that it is better to edit XML documents using a professional XML editor. Why Not Notepad? Many web developers use Notepad to edit both HTML and XML documents because Notepad is included with the most common OS and it is simple to use. Personally I often use Notepad for quick editing of simple HTML, CSS, and XML files. But, if you use Notepad for XML editing, you will soon run into problems. Notepad does not know that you are writing XML, so it will not be able to assist you. Why an XML Editor? Today XML is an important technology, and development projects use XML-based technologies like: XML Schema to define XML structures and data types XSLT to transform XML data SOAP to exchange XML data between applications WSDL to describe web services RDF to describe web resources XPath and XQuery to access XML data SMIL to define graphics To be able to write error-free XML documents, you will need an intelligent XML editor! XML Editors Professional XML editors will help you to write error-free XML documents, validate your XML against a DTD or a schema, and force you to stick to a valid XML structure. An XML editor should be able to: Add closing tags to your opening tags automatically Force you to write valid XML Verify your XML against a DTD Verify your XML against a Schema Color code your XML syntax
  • #17: &lt;?xml version=&quot;1.0&quot; encoding=&quot;WINDOWS-1251&quot;?&gt; &lt;?xml-stylesheet type=&apos;text/xsl&apos; href=&apos;ex01-1.xsl&apos;?&gt; &lt;tutorial&gt; &lt;title&gt;“Introduction to XML&quot;&lt;/title&gt; &lt;author&gt;Bob Hitch&lt;/author&gt; &lt;/tutorial&gt;