SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Similar a 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
 

Último

Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Rustenburg [(+27832195400*)] 🏥 Women's Abortion Clinic i...
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
Abortion Clinic in Bloemfontein [(+27832195400*)]🏥Safe Abortion Pills In Bloe...
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
Abortion Clinic In Stanger ](+27832195400*)[ 🏥 Safe Abortion Pills In Stanger...
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 

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