0% found this document useful (0 votes)
60 views15 pages

What Is XML: Self-Describing Data Is The Data That Describes Both Its Content and Structure. Why XML

XML (eXtensible Markup Language) is a markup language used to store and transport data. It was created to provide an easy way to store self-describing data. XML became a W3C recommendation in 1998. XML tags are not predefined and must be defined by the user. XML is platform and language independent.

Uploaded by

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

What Is XML: Self-Describing Data Is The Data That Describes Both Its Content and Structure. Why XML

XML (eXtensible Markup Language) is a markup language used to store and transport data. It was created to provide an easy way to store self-describing data. XML became a W3C recommendation in 1998. XML tags are not predefined and must be defined by the user. XML is platform and language independent.

Uploaded by

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

What is xml

 Xml (eXtensible Markup Language) is a mark up language.


 XML is designed to store and transport data.
 Xml was released in late 90’s. it was created to provide an easy to use
and store self describing data.
 XML became a W3C (world wide web consortium) Recommendation on
February 10, 1998.
 XML is not a replacement for HTML.
 XML is designed to be self-descriptive.
 XML is designed to carry data, not to display data.
 XML tags are not predefined. You must define your own tags.
 XML is platform independent and language independent.
Self-describing data is the data that describes both its content and
structure.

Why xml

Platform Independent and Language Independent: The main benefit of


xml is that you can use it to take data from a program like Microsoft SQL,
convert it into XML then share that XML with other programs and
platforms. You can communicate between two platforms which are
generally very difficult.

The main thing which makes XML truly powerful is its international
acceptance. Many corporation use XML interfaces for databases,
programming, office application mobile phones and more. It is due to its
platform independent feature.
Features and Advantages of XML

XML is widely used in the era of web development. It is also used to


simplify data storage and data sharing.
The main features or advantages of XML are given below.
1) XML separates data from HTML

If you need to display dynamic data in your HTML document, it will take
a lot of work to edit the HTML each time the data changes.

With XML, data can be stored in separate XML files. This way you can
focus on using HTML/CSS for display and layout, and be sure that
changes in the underlying data will not require any changes to the
HTML.
With a few lines of JavaScript code, you can read an external XML file
and update the data content of your web page.
2) XML simplifies data sharing

In the real world, computer systems and databases contain data in


incompatible formats.

XML data is stored in plain text format. This provides a software- and
hardware-independent way of storing data.

This makes it much easier to create data that can be shared by different
applications.
3) XML simplifies data transport

One of the most time-consuming challenges for developers is to


exchange data between incompatible systems over the Internet.

Exchanging data as XML greatly reduces this complexity, since the data
can be read by different incompatible applications.
4) XML simplifies Platform change

Upgrading to new systems (hardware or software platforms), is always


time consuming. Large amounts of data must be converted and
incompatible data is often lost.
XML data is stored in text format. This makes it easier to expand or
upgrade to new operating systems, new applications, or new browsers,
without losing data.
5) XML increases data availability

Different applications can access your data, not only in HTML pages, but
also from XML data sources.
With XML, your data can be available to all kinds of "reading machines"
(Handheld computers, voice machines, news feeds, etc), and make it
more available for blind people, or people with other disabilities.
6) XML can be 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
XML Example
XML documents create a hierarchical structure looks like a tree so it is
known as XML Tree that starts at "the root" and branches to "the
leaves".
XML Documents Must Have a Root Element

Components
 Processing Instruction
 Tags
 Elements
 Attributes
 Entities
 Comments
 Contents


 Processing Instruction
XML document begins with PI
Xml declaration

PI statement: <?xml version="1.0" encoding="ISO-8859-1"?>


<?xml version="1.0" encoding="UTF"?>
(Unicode Transformation Format) UCS(universal character set)

Tags Identifying data


start tag: < elements>

end tag: < /elements>

XML documents must contain one root element that is the parent of all
other elements:
<root>
<child>
<subchild>.....</subchild>
</child>
</root>

<student roll=”01”>
<name>John</name>
<grade>A+</grade>
</student>

Example of XML Document

XML documents uses a self-describing and simple syntax:


<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

The first line is the XML declaration. It defines the XML version (1.0) and
the encoding used (ISO-8859-1 = Latin-1/West European character set).
The next line describes the root element of the document (like saying:
"this document is a note"):

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).
ll XML Elements Must Have a Closing 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 Tags are Case Sensitive


XML tags are case sensitive. The tag <Letter> is different from the tag
<letter>.
Opening and closing tags must be written with the same case:
<message>This is correct</message>

"Opening and closing tags" are often referred to as "Start and end tags".
Use whatever you prefer. It is exactly the same thing.
XML Elements Must be Properly Nested

In HTML, you might see improperly nested elements:


<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 Attribute Values Must Always be Quoted

XML elements can have attributes in name/value pairs just like in HTML.

In XML, the attribute values must always be quoted:


<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
Entity References

Some characters have a special meaning in XML.

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>salary < 1000</message>

To avoid this error, replace the "<" character with an entity reference:
<message>salary &lt; 1000</message>

There are 5 pre-defined entity references in XML:


&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark

Only < and & are strictly illegal in XML, but it is a good habit to replace >
with &gt; as well.
Comments in XML

The syntax for writing comments in XML is similar to that of HTML:


<!-- This is a comment -->

Two dashes in the middle of a comment are not allowed:


<!-- This is an invalid -- comment -->
White-space is Preserved in XML

XML does not truncate multiple white-spaces (HTML truncates multiple


white-spaces to one single white-space):
XML: Hello Tove
HTML: Hello Tove
All elements can have text content and attributes (just like in HTML).
Another Example of XML: Books

File: books.xml

<bookstore>
<book category="COOKING">
<title lang="Eng">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="Eng">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="Eng">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Output
<bookstore>
<book category="COOKING">
<title lang="Eng">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="Eng">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="Eng">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

The root element in the example is <bookstore>. All elements in the


document are contained within <bookstore>.
The <book> element has 4 children: <title>,< author>, <year> and
<price>.
<?xml version="1.0" encoding="UTF-8"?>
<emails>
<email>
<to>Vimal</to>
<from>Sonoo</from>
<heading>Hello</heading>
<body>Hello brother, how are you!</body>
</email>
<email>
<to>Peter</to>
<from>Jack</from>
<heading>Birth day wish</heading>
<body>Happy birth day Tom!</body>
</email>
<email>
<to>James</to>
<from>Jaclin</from>
<heading>Morning walk</heading>
<body>Please start morning walk to stay fit!</body>
</email>
<email>
<to>Kartik</to>
<from>Kumar</from>
<heading>Health Tips</heading>
<body>Smoking is injurious to health!</body>
</email>
</emails>

Output

-<note>
<email>
<to>Vimal</to>
<from>Sonoo</from>
<heading>Hello</heading>
<body>Hello brother, how are you!</body>
</email>
<email>
<to>Peter</to>
<from>Jack</from>
<heading>Birth day wish</heading>
<body>Happy birth day Tom!</body>
</email>

<email>
<to>James</to>
<from>Jaclin</from>
<heading>Morning walk</heading>
<body>Please start morning walk to stay fit!</body>
</email>
<email>
<to>Kartik</to>
<from>Kumar</from>
<heading>Health Tips</heading>
<body>Smoking is injurious to health!</body>
</email>
</note>

XML Related Technologies


Here we have pointed out XML related technologies. There are following XML related
technologies:

No. Technology Meaning Description


It is a clearer and stricter version of XML. It belongs to
the family of XML markup languages. It was developed
1) XHTML Extensible html
to make html more extensible and increase inter-
operability with other data.
It is a standard document model that is used to access
XML document
2) XML DOM and manipulate XML. It defines the XML file in tree
object model
structure.
3) XSL Extensible style
it contain three sheet language i) It transforms XML into other formats, like html.
parts: ii) It is used for formatting XML to screen, paper etc.
i) XSLT (xsl
transform)
iii) It is a language to navigate XML documents.
ii) XSL
iii)XPath
XML query It is a XML based language which is used to query
4) XQuery
language XML based data.
Document type It is an standard which is used to define the legal
5) DTD
definition elements in an XML document.
XML schema It is an XML based alternative to dtd. It is used to
6) XSD
definition describe the structure of an XML document.
xlink stands for XML linking language. This is a
XML linking
7) XLink language for creating hyperlinks (external and internal
language
links) in XML documents.
It is a system for addressing components of XML based
XML pointer
8) XPointer internet media. It allows the xlink hyperlinks to point to
language
more specific parts in the XML document.
It is an acronym stands simple object access protocol. It
Simple object is XML based protocol to let applications exchange
9) SOAP
access protocol information over http. in simple words you can say that
it is protocol used for accessing web services.
web services It is an XML based language to describe web services.
10) WSDL description It also describes the functionality offered by a web
languages service.
RDF is an XML based language to describe web
Resource
resources. It is a standard model for data interchange on
11) RDF description
the web. It is used to describe the title, author, content
framework
and copyright information of a web page.
It is an XML based vector image format for two-
Scalable vector
12) SVG dimensional images. It defines graphics in XML format.
graphics
It also supports animation.
RSS is a XML-based format to handle web content
Really simple
13) RSS syndication. It is used for fast browsing for news and
syndication
updates. It is generally used for news like sites.

XML Attributes

XML elements can have attributes. By the use of attributes we can add
the information about the element.

XML attributes enhance the properties of the elements.


Note: XML attributes must always be quoted. We can use single or
double quote.
Let us take an example of a book publisher. Here, book is the element
and publisher is the attribute.
<book publisher="Tata McGraw Hill"></book>
Or
<book publisher='Tata McGraw Hill'></book>
Metadata should be stored as attribute and data should be stored as
element.
<book>
<book category="computer">
<author> A & B </author>
</book>

Data can be stored in attributes or in child elements. But there are some
limitations in using attributes, over child elements.
Why should we avoid XML attributes

Attributes cannot contain multiple values but child elements can have
multiple values.
Attributes cannot contain tree structure but child element can.
Attributes are not easily expandable. If you want to change in
attribute's values in future, it may be complicated.
Attributes cannot describe structure but child elements can.
Attributes are more difficult to be manipulated by program code.

Difference between attribute and sub-element

In the context of documents, attributes are part of markup, while sub


elements are part of the basic document contents.

In the context of data representation, the difference is unclear and may


be confusing.

Same information can be represented in two ways:


1st way:
<book publisher="Tata McGraw Hill"> </book>

2nd way:

<book>
<publisher> Tata McGraw Hill </publisher>
</book>

In the first example publisher is used as an attribute and in the second


example publisher is an element.

Both examples provide the same information but it is good practice to


avoid attribute in XML and use elements instead of attributes

XML Comments

XML comments are just like HTML comments. We know that the
comments are used to make codes more understandable other
developers.

XML Comments add notes or lines for understanding the purpose of an


XML code. Although XML is known as self-describing data but sometimes
XML comments are necessary.
Syntax

An XML comment should be written as:

<!-- Write your comment-->

You cannot nest one XML comment inside the another.


XML Comments Example

Let's take an example to show the use of comment in an XML example:

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


<!--Students marks are uploaded by months-->
<students>
<student>
<name>Ratan</name>
<marks>70</marks>
</student>
<student>
<name>Aryan</name>
<marks>60</marks>
</student>
</students>
Output
<!--Students marks are uploaded by months-->
<students>
<student>
<name>Ratan</name>
<marks>70</marks>
</student>
<student>
<name>Aryan</name>
<marks>60</marks>
</student>
</students>
XML Tree Structure

An XML document has a self descriptive structure. It forms a tree


structure which is referred as an XML tree. The tree structure makes
easy to describe an XML document.

A tree structure contains root element (as parent), child element and so
on. It is very easy to traverse all succeeding branches and sub-branches
and leaf nodes starting from the root.

Example of an XML document

<?xml version="1.0"?>
<college>
<student>
<firstname>Tamanna</firstname>
<lastname>Bhatia</lastname>
<contact>09990449935</contact>
<email>[email protected]</email>
<address>
<city>Ghaziabad</city>
<state>Uttar Pradesh</state>
<pin>201007</pin>
</address>
</student>
</college>

Output
<college>
<student>
<firstname>Tamanna</firstname>
<lastname>Bhatia</lastname>
<contact>09990449935</contact>
<email>[email protected]</email>
<address>
<city>Ghaziabad</city>
<state>Uttar Pradesh</state>
<pin>201007</pin>
</address>
</student>
</college>

You might also like