0% found this document useful (0 votes)
2 views14 pages

2 xml

XML, or eXtensible Markup Language, is a markup language designed for storing and transporting data in a human- and machine-readable format. Unlike HTML, which focuses on data presentation, XML is focused on data structure and allows for user-defined tags. Key features of XML include extensibility, platform independence, and the ability to define custom tags and attributes.

Uploaded by

ayushth1997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

2 xml

XML, or eXtensible Markup Language, is a markup language designed for storing and transporting data in a human- and machine-readable format. Unlike HTML, which focuses on data presentation, XML is focused on data structure and allows for user-defined tags. Key features of XML include extensibility, platform independence, and the ability to define custom tags and attributes.

Uploaded by

ayushth1997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

XML

 A markup language is a computer language that uses


XML stands for eXtensible Markup Language. Tags to define elements within a document.
XML was designed to store and transport data.
XML was designed to be both human- and machine-readable. <p>
XML is a software- and hardware-independent tool for storing and transporting data.
XML is a markup language much like HTM This is a paragraph.

 The Difference Between XML and HTML </p>

XML was designed to carry data - with focus on what data is


HTML was designed to display data - with focus on how data looks
XML tags are not predefined like HTML tags are
 Difference between HTML and XML
HTML XML
HTML stands for Hyper Text Markup Language. XML stands for Extensible Markup Language.
HTML tags are used for displaying the data. XML tags are used for describing the data not for displaying.
HTML tags are predefined tags. XML tags are user-defined tags.
HTML is static in nature. XML is dynamic in nature.
It has an extension of .html and .htm It has an extension of .xml
There are limited number of tags in HTML. XML tags are extensible.
HTML does not carry data it just displays it. XML carries the data to and from the database.
 XML Features

It is extensible and human-readable.


It is platform and language independent.
It preserves white space.
Overall simplicity.
Self-descriptive nature.
XML tags are not predefined. You need to define your customized tags.
XML was designed to carry data, not to display that data.
Mark-up code of XML is easy to understand for a human.
Well-structured format is easy to read and write from programs.
XML is an extensible markup language like HTML.
 XML Encoding
Encoding is the conversion of Unicode characters to their binary representation. UTF is used for XML encoding. UTF stands
for UCS (UCS stands for Universal Character Set) Transformation Format.

Mainly, there are two types of UTF encoding.

UTF-8 : UTF-8 uses 8-bits to represent the characters.


Example:
<?xml version="1.0"
encoding="UTF-8"?>

UTF-16:
It uses 16-bits to represent the characters.
Example:

<?xml version="1.0" encoding="UTF-16"?


>

You can use encoding inside the XML declaration. UTF-8 is the default encoding in XML.
 XML Syntax
The below code segment shows the basic XML syntax.

<?xml version = "1.0" encoding = "UTF-8" ?>


<root>
<child>
<subchild>.....</subchild>
</child>
</root>

 XML Declaration
XML declaration consists of the XML version, character encoding or/and standalone status. The declaration is optional.
 Syntax for XML Declaration
The below code segment shows the syntax for XML declaration.

<?xml version="version_number" encoding="character_encoding“


standalone="yes_or_no" ?>
 XML Declaration Rules
Following are XML declaration rules.
If the XML declaration is present, it must be the first thing that appears.
The XML declaration is case sensitive, and it must start with the lowercased <?xml.
It has no closing tag.
What is a DTD?
DTD stands for Document Type Definition.
A DTD defines the structure and the legal
 Example of XML Declaration elements and attributes of an XML document.
Following code segment shows an example of an XML declaration.

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

 The standalone directive is an optional attribute on the XML declaration.


Valid values are yes or no, where no is the default value.
 The attribute is relevant when a DTD is used.
 standalone="yes" means that the XML processor must use the DTD for validation only.
 XML Comments
Comments are optional. Adding comments help to understand the document content.
 Syntax for XML Comments
A comment begins with <!– and ends with –>.
Following code segment shows the syntax for XML comments.

<!-- Add your comment here -->


 XML Tags and Elements
Tags work as pairs except for declarations. Every tag pair consists of an opening tag (also known as the start tag) and a
closing tag (also known as the end tag).
Tag names are enclosed in <>. For a particular tag pair, the start and end tags must be identical except the
end tag has / after the <.

<name>...</name>

Anything between the opening and closing tags is referred to as content.


Opening tag, content, and closing tag, altogether, is referred to as an element.

Opening tag + content + closing tag = an element

Elements may also contain attributes.

<age>20</age> Note: Tag name also referred to as an element or element name.


<age> – opening tag
In the above element, 25 – content
age is the name of the element. </age> – closing tag.
 If there is no content between the tags, as shown below, it referred to as empty tags.

<result></result>

 XML Tag and Element Rules


Following list shows XML tag and element rules.

Tags are case sensitive.

 Example:
Correct: <age>20</age>

Wrong:
<age>20</Age>

Note: AGE, Age, and age are three different names in XML.
 All XML documents must contain a single root element.

All elements must have a closing tag (except for declarations).


A tag name must begin with a letter or an underscore, and it cannot start with the XML.
A tag name can contain letters, digits, hyphens, underscores, and periods. Hyphens, underscore, and periods are the
only punctuation marks allowed.
A tag name cannot contain spaces.
All elements must be nested properly.

 Example:

Correct: <b><u>This text is bold and


underlined</u></b>

Wrong: <b><u>This text is bold and


underlined.</b></u>
 XML Attributes
Attribute for an element is placed after the tag name in the start tag. You can add more than one attribute for a single
element with different attribute names.
Let’s consider the below XML document.

<company name="ABC Holdings“


location="London"> <chairman>Mr. John</chairman>
<gm>Mr. Wood</gm>
</company>

There are two attributes in the company element, i.e. name and location.

Let’s study the name attribute,


name=”ABC Holdings” – an attribute
name – attribute name
ABC Holdings – attribute value

Note: An attribute name is also known as an attribute.


Also, note that in the above example, the company is the root element.
 XML Attribute Rules
The below list shows XML attribute rules.
 Attribute values must be within quotes.
An element cannot contain several attributes with the same name.

 Attribute versus Element

Let’s consider documents A and B given below.


Document A:
<teacher subject="English">
<name>Mr. John</name>
<qualification>Graduate</qualification>
</teacher>
Document B:
<teacher>
<subject>English</subject>
<name>Mr. John</name>
<qualification>Graduate</qualification>
</teacher>

In document A, the subject is an attribute.


In document B, the subject is an element.
 XML Entities
What are XML Entities?
In simple terms, entities are a way of representing special characters. Entities are also known as entity references.
Why You Need XML Entities?
Some characters (such as “, &, <, and so on) are reserved in XML. They are referred to as special characters and
cannot be directly used for other purposes.

For example, the < and > symbols are used for tags. You cannot directly type from the keyboard for less than and
greater than signs. Instead, you need to use entities.

 Following table shows some of the popular XML entities.


Character Description Entity Name Usage
Quotation mark
” quot &quot;
(double quote)
& Ampersand amp &amp;
Apostrophe (single
‘ apos &apos;
quote)
< Less than sign lt &lt;
> Greater than sign gt &gt;
Example:
<friend>
<name>My friends are Akash &amp; Sunil.</name>
</friend>

You might also like