ݺߣ

ݺߣShare a Scribd company logo
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 - ExtensibleMarkupLanguage for Network Security.pptx
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.
XML - ExtensibleMarkupLanguage for Network Security.pptx
XML - ExtensibleMarkupLanguage for Network Security.pptx
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 - ExtensibleMarkupLanguage for Network Security.pptx (20)

PHP XML
PHP XMLPHP XML
PHP XML
YellGhost
Xml tutorial
Xml tutorialXml tutorial
Xml tutorial
IT
BITM3730 10-31.pptx
BITM3730 10-31.pptxBITM3730 10-31.pptx
BITM3730 10-31.pptx
MattMarino13
BITM3730 10-18.pptx
BITM3730 10-18.pptxBITM3730 10-18.pptx
BITM3730 10-18.pptx
MattMarino13
Xml iet 2015
Xml iet 2015Xml iet 2015
Xml iet 2015
kiransurariya
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
amare63
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
Abhishek Kesharwani
02 well formed and valid documents
02 well formed and valid documents02 well formed and valid documents
02 well formed and valid documents
Baskarkncet
Web Technology Part 4
Web Technology Part 4Web Technology Part 4
Web Technology Part 4
Thapar Institute
Xml material
Xml materialXml material
Xml material
xavier john
Xml material
Xml materialXml material
Xml material
prathap kumar
Xml material
Xml materialXml material
Xml material
prathap kumar
XML
XMLXML
XML
Vahideh Zarea Gavgani
Unit 2.2
Unit 2.2Unit 2.2
Unit 2.2
Abhishek Kesharwani
Web Development Course - XML by RSOLUTIONS
Web Development Course - XML by RSOLUTIONSWeb Development Course - XML by RSOLUTIONS
Web Development Course - XML by RSOLUTIONS
RSolutions
Intro xml
Intro xmlIntro xml
Intro xml
sana mateen
paper about xml
paper about xmlpaper about xml
paper about xml
عبدالغني الهجار
Xml description
Xml descriptionXml description
Xml description
sonam gupta
XML DTD Validate
XML DTD ValidateXML DTD Validate
XML DTD Validate
jomerson remorosa
Xml 1
Xml 1Xml 1
Xml 1
pavishkumarsingh

Recently uploaded (20)

Metaverse Meetup: Explore Mulesoft MAC Project
Metaverse Meetup: Explore  Mulesoft MAC ProjectMetaverse Meetup: Explore  Mulesoft MAC Project
Metaverse Meetup: Explore Mulesoft MAC Project
GiulioPicchi
iTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free DownloadiTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free Download
lr74xqnvuf
Online Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi NcrOnline Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi Ncr
Home
Computer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .pptComputer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .ppt
jaysen110
OutSystems User Group Utrecht February 2025.pdf
OutSystems User Group Utrecht February 2025.pdfOutSystems User Group Utrecht February 2025.pdf
OutSystems User Group Utrecht February 2025.pdf
mail496323
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
Consequences and Principles of Software Quality v1.0
Consequences and Principles of Software Quality v1.0Consequences and Principles of Software Quality v1.0
Consequences and Principles of Software Quality v1.0
Yann-Gaël Guéhéneuc
SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?
kiran10101khan
Code or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose BothCode or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose Both
Applitools
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
Alluxio, Inc.
Adobe Illustrator Crack Free Download 2025 latest version
Adobe Illustrator Crack Free Download 2025 latest versionAdobe Illustrator Crack Free Download 2025 latest version
Adobe Illustrator Crack Free Download 2025 latest version
saniasabbba
AI Agents and More:Build Your AI Assistans
AI Agents and More:Build Your AI AssistansAI Agents and More:Build Your AI Assistans
AI Agents and More:Build Your AI Assistans
HusseinMalikMammadli
Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP SolutionsWhy Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Absolute ERP
Wondershare Filmora Crack Free Download
Wondershare Filmora  Crack Free DownloadWondershare Filmora  Crack Free Download
Wondershare Filmora Crack Free Download
zqeevcqb3t
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber ScaleAI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
Alluxio, Inc.
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
haroonsaeed605
Cybersecurity & Innovation: The Future of Mobile App Development
Cybersecurity & Innovation: The Future of Mobile App DevelopmentCybersecurity & Innovation: The Future of Mobile App Development
Cybersecurity & Innovation: The Future of Mobile App Development
iProgrammer Solutions Private Limited
SE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.pptSE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.ppt
theworldimagine985
Metaverse Meetup: Explore Mulesoft MAC Project
Metaverse Meetup: Explore  Mulesoft MAC ProjectMetaverse Meetup: Explore  Mulesoft MAC Project
Metaverse Meetup: Explore Mulesoft MAC Project
GiulioPicchi
iTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free DownloadiTop VPN Latest Version 2025 Crack Free Download
iTop VPN Latest Version 2025 Crack Free Download
lr74xqnvuf
Online Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi NcrOnline Software Testing Training Institute in Delhi Ncr
Online Software Testing Training Institute in Delhi Ncr
Home
Computer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .pptComputer Architecture Patterson chapter 1 .ppt
Computer Architecture Patterson chapter 1 .ppt
jaysen110
OutSystems User Group Utrecht February 2025.pdf
OutSystems User Group Utrecht February 2025.pdfOutSystems User Group Utrecht February 2025.pdf
OutSystems User Group Utrecht February 2025.pdf
mail496323
Minitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free DownloadMinitool Partition Wizard Crack Free Download
Minitool Partition Wizard Crack Free Download
v3r2eptd2q
Consequences and Principles of Software Quality v1.0
Consequences and Principles of Software Quality v1.0Consequences and Principles of Software Quality v1.0
Consequences and Principles of Software Quality v1.0
Yann-Gaël Guéhéneuc
SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?SketchUp Pro Crack [2025]-Free Download?
SketchUp Pro Crack [2025]-Free Download?
kiran10101khan
Code or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose BothCode or No-Code Tests: Why Top Teams Choose Both
Code or No-Code Tests: Why Top Teams Choose Both
Applitools
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
AI/ML Infra Meetup | Building Production Platform for Large-Scale Recommendat...
Alluxio, Inc.
Adobe Illustrator Crack Free Download 2025 latest version
Adobe Illustrator Crack Free Download 2025 latest versionAdobe Illustrator Crack Free Download 2025 latest version
Adobe Illustrator Crack Free Download 2025 latest version
saniasabbba
AI Agents and More:Build Your AI Assistans
AI Agents and More:Build Your AI AssistansAI Agents and More:Build Your AI Assistans
AI Agents and More:Build Your AI Assistans
HusseinMalikMammadli
Douwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-LatestDouwan Preactivated Plus Crack 2025-Latest
Douwan Preactivated Plus Crack 2025-Latest
mubeen010khan
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP SolutionsWhy Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Why Every Cables and Wires Manufacturer Needs a Cloud-Based ERP Solutions
Absolute ERP
Wondershare Filmora Crack Free Download
Wondershare Filmora  Crack Free DownloadWondershare Filmora  Crack Free Download
Wondershare Filmora Crack Free Download
zqeevcqb3t
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
ChatGPT and DeepSeek: Which AI Tool Delivers Better User Experience?
Ava Isley
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber ScaleAI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
AI/ML Infra Meetup | Deployment, Discovery and Serving of LLMs at Uber Scale
Alluxio, Inc.
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
AnyDesk Pro 3.7.0 Crack License Key Free Download 2025 [Latest]
haroonsaeed605
SE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.pptSE- Lecture 5 for software development.ppt
SE- Lecture 5 for software development.ppt
theworldimagine985

XML - ExtensibleMarkupLanguage 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).
  • 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.
  • 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