Introduction to XML

This section presents you a brief introduction to key terminologies used in relation to xml.


Share on Google+Share on Google+

Introduction to XML


This section presents you a brief introduction to key terminologies used in relation to xml.

Introduction to XML

An xml file consists of various elements. This section presents you a brief introduction to key terminologies used in relation to xml.

Here is a sample xml code:

<?xml version="1.0" encoding="UTF-8"?>
    <book-name type="technical">My XML Book</book-name>
    <book-image src="images/myxml.gif"/>
    <short-desc>This book is good for beginners in XML. This book helps beginners to learn xml easily and use XML concepts in their real development.</short-desc>

1. XML Declaration

All xml documents starts with xml declaration which provides essential information about the syntactic basis of an XML document and identifies the document as XML document. XML declaration is not necessary, but it's the best way to declare it as xml document. Ex.

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

version-Version of the XML standard that the XML document conforms to. It is required if the XML declaration is declared.

encoding- Encoding name of the most common character sets like UTF-8, UTF-16, ISO-10646-UCS-2 etc.

2. Root element

XML documents contains an element which is the parent of all other child elements. This first element of the document is called the root element. Ex.


3. Tag

XML tags are similar as in html. If you have used html then it is easy to understand xml tags. Tag starts with < and ends with > characters. Tags can have attributes to provide information about tag.

<book-name type="technical">

These are of three types:

1. Start tag

(Ex. <book-name>)

2. End tag

(Ex. </book-name>)

3. Empty-element tag

This is also known as bodyless tag. It has a start tag but does not have a matching end tag.

<book-image src="images/myxml.gif"/>

Opening and closing tags collectively are called tag pair.

Xml tags follow some rules given below:

  1. Tags must be nested properly.
  2. Tags are case sensitive.
  3. They must have a beginning and an end and enclosed in < and >.

4. Element

The content between start tag and end tag including tags is called element. An element can contain other child elements. Ex

<book-name type="technical">My XML Book</book-name>

1. XML Elements are Extensible.

2. XML Elements have Relationships as parents and children.

XML Naming Rules:

Any name can be used, no words are reserved but it must follow naming rules given below:

  1. Can have letters, numbers and other characters
  2. Must not start with a number or punctuation character
  3. Must not start with the letters xml (or XML, or Xml, etc)
  4. Cannot contain spaces

5. Attributes

Xml elements can contain attributes which provides some additional information about element. For example, book-name element contains "type" attribute and it is assigned value "technical".


Attributes often provide information that is not a part of the data. Attribute values must always be enclosed in either single or double quotes. If the value of the attribute contains double quotes then use single quote to enclose the value of the attribute.

There are some problems using attributes as given below:

  1. Can not contain multiple values
  2. Difficult to manipulate by program code
  3. Unable to describe structures
  4. Not easy to test against a DTD
  5. Not expandable for future enhancements



Posted on: October 30, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles