SlideShare a Scribd company logo
1 of 35
XML - Extensible Markup
Language
XML - Extensible Markup Language
Learning outcome:
After completing this lesson you will be able to explain the need
for XML and describe basic concepts and components of the
language. Also you will be able to markup data using XML.
XML - Extensible Markup Language
Lesson Outline:
1. Introduction to XML
2. XML Syntax Rules
3. Components of XML
4. XML Naming Rules
XML - Extensible Markup Language
Learning outcome:
After completing this lesson you will be able to explain the need
for XML and describe basic concepts and components of the
language. Also you will be able to markup data using XML.
XML - Extensible Markup Language
XML is designed to transport and store data.
XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to carry data, not to display data
XML tags are not predefined. You must define your own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation
The Difference Between XML and HTML
XML is not a replacement for HTML.
XML and HTML were designed with different goals:
XML was designed to transport and store data, with focus o
n
what data is
HTML was designed to display data, with focus on how data
looks
HTML is about displaying information, while XML is about
carrying information.
XML was introduced due to a number of reasons
1.HTML has become a complex language with the latest version
having more than 100 different tags.
1.More tags are needed to handle the growing technologies such as
E-commerce.
1.Mobile machines such as PDA’S don’t have enough processing
power to handle such as a complex language. Therefore better
structuring required.
1.XML is text based, platform and language independent.
How Can XML be Used?
XML is used in many aspects of web development, often to simplify
data storage and sharing.
•XML Separates Data from HTML
•XML Simplifies Data Sharing
•XML Simplifies Data Transport
•XML Simplifies Platform Changes
•XML Makes Your Data MoreAvailable
XML is Used to Create New Internet Languages
A lot of new Internet languages are created with XML.
Here are some examples:
•XHTML
•WSDL for describing available web services
•WAP and WML as markup languages for handheld devices
•RSS languages for news feeds
•RDF and OWL for describing resources and ontology
•SMIL for describing multimedia for the web
WSDL - Web Service Definition Language
WAP - Wireless Application Protocol
WML – Wireless Markup Language
RSS - Rich Site Summary - Really Simple Syndication
RDF - Resource Description Framework
OWL - Web Ontology Language
SMIL - Synchronized Multimedia Integration Language
XML Tree
XML documents form a tree structure that starts at "the root" and
branches to "the leaves".
An Example XML Document
XML documents use a self-describing and simple syntax:
<?xml version="1.0" ?>
<student>
<stNo>1001</stNo>
<stName>Amal</stName>
<stAge>20</stAge>
</student>
XML Tree
The first line is the XML declaration. It defines the XML version (1.0)
and the encoding used.
The next line describes the root element of the document (like
saying: "this document is a note"):
<student>
The next 3 lines describe 3 child elements of the root:
<stNo>1001</stNo>
<stName>Amal</stName>
<stAge>20</stAge>
And finally the last line defines the end of the root element:
</student>
XML Documents Form a Tree Structure
XML documents must contain a root element.
This element is "the parent" of all other elements.
The elements in an XML document form a document tree.
The tree starts at the root and branches to the lowest level of the
tree.
All elements can have sub elements (child elements):
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
The terms parent, child, and sibling are used to describe the
relationships between elements. Parent elements have children.
Children on the same level are called siblings (brothers or sisters).
XML Syntax Rules
•Tag names are case sensitive.
With XML, the tag <Letter> is different from the tag <letter>.
Opening and closing tags must be written with the same
case:
<Message>This is incorrect</message>
<message>This is correct</message>
•Every opening tag must have a corresponding
closing tag (unless it is as an empty tag).
In XML, it is illegal to omit the closing tag. All elements must have a
closing tag:
<p>This is a paragraph.</p>
<br />
XML Syntax Rules
•All XML elements must be properly nested:
<b><i>This text is bold and italic</b></i>
In XML, all elements must be properly nested within each
other:
<b><i>This text is bold and italic</i></b>
In the example above, "Properly nested" simply means
that since the <i> element is opened inside the <b>
element, it must be closed inside the <b> element.
XML Syntax Rules
•XML Documents Must Have a Root Element
XML documents must contain one element that is the parent of all
other elements. This element is called the root element.
<root>
<child>
<subchild>.....</subchild>
</child>
</root>
XML Syntax Rules
•XML Attribute Values Must be Quoted
XML elements can have attributes in name/value pairs just like in
HTML.
In XML, the attribute values must always be quoted.
Study the two XML documents below. The first one is incorrect, the
second is correct:
<student stNo=1001>
<stNo>1001</stNo>
<stName>Amal</stName>
<stAge>20</stAge>
</student>
<student stNo=”1001”>
<stNo>1001</stNo>
<stName>Amal</stName>
<stAge>20</stAge>
</student>
Entity References
Some characters have a special meaning in XML
Entity References
If you place a character like "<" inside an XML element, it will
generate an error because the parser interprets it as the start of a
new element.
This will generate an XML error:
<message>if salary < 25000 then</message>
To avoid this error, replace the "<" character with an entity
reference:
<message>if salary &lt; 25000 then</message>
Comments in XML
The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->
HTML truncates multiple white-space characters to one single
white-space:
With XML, the white-space in a document is not truncated.
Well Formed XML
XML documents that conform to the syntax rules above are said to
be "Well Formed" XML documents.
XML has 3 fundamental building blocks: elements,
attributes, and values.
An XML document contains XML Elements
An XML element is everything from (including) the element's start
tag to (including) the element's end tag.
An element can contain:
•other elements
•text
•attributes
•or a mix of all of the above...
An element is used to describe or contain a piece of Information
Elements consist of two tags: an opening tag and a closing tag
In the example above, <bookstore> and <book> have element
contents, because they contain other elements. <book> also has an
attribute (category="CHILDREN"). <title>, <author>, <year>, and
<price> have text content because they contain text.
Empty XML Elements
An alternative syntax can be used for XML elements with no
content:
Instead of writing a book element (with no content) like this:
<book></book>
It can be written like this:
<book />
This sort of element syntax is called self-closing
XML Naming Rules
XML elements must follow these naming rules:
•Names can contain letters, numbers, and other
characters
•Names cannot start with a number or punctuation
character
•Names cannot start with the letters xml (or XML, or Xml,
etc)
•Names cannot contain spaces
Any name can be used, no words are reserved.
Best Naming Practices
•Make names descriptive: <first_name>, <last_name>.
•Make names short and simple, like this: <book_title> not like this:
<the_title_of_the_book>.
•Avoid "-". If you name something "first-name," some software
may think you want to subtract name from first.
•Avoid ".". If you name something "first.name," some software
may think that "name" is a property of the object "first.“
•Avoid ":". Colons are reserved to be used for something called
namespaces (more later).
•Non-English letters like éòá are perfectly legal in XML, but watch
out for problems if your software doesn't support them.
Naming Styles
There are no naming styles defined for XML elements. But here are
some commonly used:
XML Attributes
•XML elements can have attributes, just like HTML.
•Attributes provide additional information about an element.
•Attributes often provide information that is not a part of the data.
•In the example below, the file type is irrelevant to the data, but
can be important to the software that wants to manipulate the
element:
<file type="gif">computer.gif</file>
XML Attributes Must be Quoted
•Attribute values must always be quoted. Either single or double
quotes can be used.
•For a person's sex, the person element can be written like this:
<person sex="female"> or <person sex=‘female’>
•If the attribute value itself contains double quotes you can use single
quotes, like in this example:
<gangster name='George "Shotgun" Ziegler'>
or you can use character entities:
<gangster name="George &quot;Shotgun&quot; Ziegler">
XML Elements vs. Attributes
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
•In the first example sex is an attribute. In the last, sex is an element.
Both examples provide the same information.
Avoid XML Attributes
Some of the problems with using attributes are:
• Attributes cannot contain multiple values (elements can)
• Attributes cannot contain tree structures (elements can)
• Attributes are not easily expandable (for future changes)
Attributes are difficult to read and maintain. Use elements for data. Use
attributes for information that is not relevant to the data.
XML Attributes for Metadata
Sometimes ID references are assigned to elements. These IDs can be
used to identify XML elements in much the same way as the id
attribute in HTML
<messages>
<note id="501">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note id="502">
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not</body>
</note>
</messages>
The id attributes above are for identifying the different notes. It is not a part of the
note itself. Here is that metadata (data about data) should be stored as attributes,
and the data itself should be stored as elements
Questions
dherath10@gmail.com

More Related Content

Similar to XML - Extensible Markup Language for Network Security.pptx

Similar to XML - Extensible Markup Language for Network Security.pptx (20)

PHP XML
PHP XMLPHP XML
PHP XML
 
Xml tutorial
Xml tutorialXml tutorial
Xml tutorial
 
BITM3730 10-31.pptx
BITM3730 10-31.pptxBITM3730 10-31.pptx
BITM3730 10-31.pptx
 
BITM3730 10-18.pptx
BITM3730 10-18.pptxBITM3730 10-18.pptx
BITM3730 10-18.pptx
 
Xml iet 2015
Xml iet 2015Xml iet 2015
Xml iet 2015
 
chapter 4 web authoring unit 4 xml.pptx
chapter 4 web authoring  unit 4 xml.pptxchapter 4 web authoring  unit 4 xml.pptx
chapter 4 web authoring unit 4 xml.pptx
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
02 well formed and valid documents
02 well formed and valid documents02 well formed and valid documents
02 well formed and valid documents
 
Web Technology Part 4
Web Technology Part 4Web Technology Part 4
Web Technology Part 4
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
XML
XMLXML
XML
 
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
 
Web Development Course - XML by RSOLUTIONS
Web Development Course - XML by RSOLUTIONSWeb Development Course - XML by RSOLUTIONS
Web Development Course - XML by RSOLUTIONS
 
Intro xml
Intro xmlIntro xml
Intro xml
 
paper about xml
paper about xmlpaper about xml
paper about xml
 
Xml description
Xml descriptionXml description
Xml description
 
XML DTD Validate
XML DTD ValidateXML DTD Validate
XML DTD Validate
 
Xml 1
Xml 1Xml 1
Xml 1
 

Recently uploaded

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

XML - Extensible Markup Language for Network Security.pptx

  • 1. XML - Extensible Markup Language
  • 2. XML - Extensible Markup Language Learning outcome: After completing this lesson you will be able to explain the need for XML and describe basic concepts and components of the language. Also you will be able to markup data using XML.
  • 3. XML - Extensible Markup Language Lesson Outline: 1. Introduction to XML 2. XML Syntax Rules 3. Components of XML 4. XML Naming Rules
  • 4. XML - Extensible Markup Language Learning outcome: After completing this lesson you will be able to explain the need for XML and describe basic concepts and components of the language. Also you will be able to markup data using XML.
  • 5. XML - Extensible Markup Language XML is designed to transport and store data. XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation
  • 6. The Difference Between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data, with focus o n what data is HTML was designed to display data, with focus on how data looks HTML is about displaying information, while XML is about carrying information.
  • 7. XML was introduced due to a number of reasons 1.HTML has become a complex language with the latest version having more than 100 different tags. 1.More tags are needed to handle the growing technologies such as E-commerce. 1.Mobile machines such as PDA’S don’t have enough processing power to handle such as a complex language. Therefore better structuring required. 1.XML is text based, platform and language independent.
  • 8. How Can XML be Used? XML is used in many aspects of web development, often to simplify data storage and sharing. •XML Separates Data from HTML •XML Simplifies Data Sharing •XML Simplifies Data Transport •XML Simplifies Platform Changes •XML Makes Your Data MoreAvailable
  • 9. XML is Used to Create New Internet Languages A lot of new Internet languages are created with XML. Here are some examples: •XHTML •WSDL for describing available web services •WAP and WML as markup languages for handheld devices •RSS languages for news feeds •RDF and OWL for describing resources and ontology •SMIL for describing multimedia for the web WSDL - Web Service Definition Language WAP - Wireless Application Protocol WML – Wireless Markup Language RSS - Rich Site Summary - Really Simple Syndication RDF - Resource Description Framework OWL - Web Ontology Language SMIL - Synchronized Multimedia Integration Language
  • 10. XML Tree XML documents form a tree structure that starts at "the root" and branches to "the leaves". An Example XML Document XML documents use a self-describing and simple syntax: <?xml version="1.0" ?> <student> <stNo>1001</stNo> <stName>Amal</stName> <stAge>20</stAge> </student>
  • 11. XML Tree The first line is the XML declaration. It defines the XML version (1.0) and the encoding used. The next line describes the root element of the document (like saying: "this document is a note"): <student> The next 3 lines describe 3 child elements of the root: <stNo>1001</stNo> <stName>Amal</stName> <stAge>20</stAge> And finally the last line defines the end of the root element: </student>
  • 12. XML Documents Form a Tree Structure XML documents must contain a root element. This element is "the parent" of all other elements. The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. All elements can have sub elements (child elements): <root> <child> <subchild>.....</subchild> </child> </root> The terms parent, child, and sibling are used to describe the relationships between elements. Parent elements have children. Children on the same level are called siblings (brothers or sisters).
  • 13.
  • 14. XML Syntax Rules •Tag names are case sensitive. With XML, the tag <Letter> is different from the tag <letter>. Opening and closing tags must be written with the same case: <Message>This is incorrect</message> <message>This is correct</message> •Every opening tag must have a corresponding closing tag (unless it is as an empty tag). In XML, it is illegal to omit the closing tag. All elements must have a closing tag: <p>This is a paragraph.</p> <br />
  • 15. XML Syntax Rules •All XML elements must be properly nested: <b><i>This text is bold and italic</b></i> In XML, all elements must be properly nested within each other: <b><i>This text is bold and italic</i></b> In the example above, "Properly nested" simply means that since the <i> element is opened inside the <b> element, it must be closed inside the <b> element.
  • 16. XML Syntax Rules •XML Documents Must Have a Root Element XML documents must contain one element that is the parent of all other elements. This element is called the root element. <root> <child> <subchild>.....</subchild> </child> </root>
  • 17. XML Syntax Rules •XML Attribute Values Must be Quoted XML elements can have attributes in name/value pairs just like in HTML. In XML, the attribute values must always be quoted. Study the two XML documents below. The first one is incorrect, the second is correct: <student stNo=1001> <stNo>1001</stNo> <stName>Amal</stName> <stAge>20</stAge> </student> <student stNo=”1001”> <stNo>1001</stNo> <stName>Amal</stName> <stAge>20</stAge> </student>
  • 18. Entity References Some characters have a special meaning in XML
  • 19. Entity References If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. This will generate an XML error: <message>if salary < 25000 then</message> To avoid this error, replace the "<" character with an entity reference: <message>if salary &lt; 25000 then</message>
  • 20. Comments in XML The syntax for writing comments in XML is similar to that of HTML. <!-- This is a comment --> HTML truncates multiple white-space characters to one single white-space: With XML, the white-space in a document is not truncated.
  • 21. Well Formed XML XML documents that conform to the syntax rules above are said to be "Well Formed" XML documents. XML has 3 fundamental building blocks: elements, attributes, and values.
  • 22. An XML document contains XML Elements An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain: •other elements •text •attributes •or a mix of all of the above... An element is used to describe or contain a piece of Information Elements consist of two tags: an opening tag and a closing tag
  • 23. In the example above, <bookstore> and <book> have element contents, because they contain other elements. <book> also has an attribute (category="CHILDREN"). <title>, <author>, <year>, and <price> have text content because they contain text.
  • 24. Empty XML Elements An alternative syntax can be used for XML elements with no content: Instead of writing a book element (with no content) like this: <book></book> It can be written like this: <book /> This sort of element syntax is called self-closing
  • 25. XML Naming Rules XML elements must follow these naming rules: •Names can contain letters, numbers, and other characters •Names cannot start with a number or punctuation character •Names cannot start with the letters xml (or XML, or Xml, etc) •Names cannot contain spaces Any name can be used, no words are reserved.
  • 26. Best Naming Practices •Make names descriptive: <first_name>, <last_name>. •Make names short and simple, like this: <book_title> not like this: <the_title_of_the_book>. •Avoid "-". If you name something "first-name," some software may think you want to subtract name from first. •Avoid ".". If you name something "first.name," some software may think that "name" is a property of the object "first.“ •Avoid ":". Colons are reserved to be used for something called namespaces (more later). •Non-English letters like éòá are perfectly legal in XML, but watch out for problems if your software doesn't support them.
  • 27. Naming Styles There are no naming styles defined for XML elements. But here are some commonly used:
  • 28. XML Attributes •XML elements can have attributes, just like HTML. •Attributes provide additional information about an element. •Attributes often provide information that is not a part of the data. •In the example below, the file type is irrelevant to the data, but can be important to the software that wants to manipulate the element: <file type="gif">computer.gif</file>
  • 29. XML Attributes Must be Quoted •Attribute values must always be quoted. Either single or double quotes can be used. •For a person's sex, the person element can be written like this: <person sex="female"> or <person sex=‘female’> •If the attribute value itself contains double quotes you can use single quotes, like in this example: <gangster name='George "Shotgun" Ziegler'> or you can use character entities: <gangster name="George &quot;Shotgun&quot; Ziegler">
  • 30. XML Elements vs. Attributes <person sex="female"> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> <person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> •In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information.
  • 31.
  • 32.
  • 33. Avoid XML Attributes Some of the problems with using attributes are: • Attributes cannot contain multiple values (elements can) • Attributes cannot contain tree structures (elements can) • Attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.
  • 34. XML Attributes for Metadata Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML <messages> <note id="501"> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note id="502"> <to>Jani</to> <from>Tove</from> <heading>Re: Reminder</heading> <body>I will not</body> </note> </messages> The id attributes above are for identifying the different notes. It is not a part of the note itself. Here is that metadata (data about data) should be stored as attributes, and the data itself should be stored as elements