December 4, 2015

Introduction to XML – Part 1

In this blog …I’m going to give a quick introduction to XML into two part, in this part will explain the basic structure and rule of xml with some examples. Second part will cover extra details of xml with some special cases.

 What is XML ?

  • XML considered to be a very important language these days, it’s considered to be the common infrastructure between different platform.
  • XML is a language for describing data and the structure of data.

  •  XML data is contained in a document, which can be a file, a stream, or any other storage media.

  •  XML document have the following declaration :<?xml version="1.0"?>
  • Example : XML encoding for Latin language :<?xml version="1.0“ encoding=“ISO-8859-1” ?>
Note : Encoding attribute is optional because XML can know the encoding from first 5 (i.e. “<?xml”)

  •  XML declarations considered to be processing instructions for XML parser.

  •   Processing instruction begin with “<?” and end with “?>”.

  •  The following represent an XML example:

XML document example


  •  As you see in previous example , xml element start with <?xml version="1.0"?> part 
  • <Books> element a root elements.
  • “Book”, “title”, “author” & “price” are elements, note that some elements have sub elements such as book.
  • Note that the “Category” phrase inside book element called attribute.
  • Values between elements tags considered as the real data, however elements and attributes present the xml structure, structure of XML always give an indicator how the data will be look like.

XML restriction 

  • Unlike HTML , XML requires start tags to be closed.
  •  XML is Case-Sensitive.
  • XML document called DOM (document Object Modules) , Every document can be displayed as tree named a DOM.

XML elements

  • XML Elements name rules :

1.    Consist of letters , underscore followed by letters , digits , periods , hyphens and underscore.
2.    Space are not allowed.
3.    Elements are extensible and meaningful.
4.    Must start with number or punctuation character.
5.    Must not start with with “xml” or “XML”
a.    Try to avoid “-” and “.” in your elements names.

        Example: the highlighted in yellow present elements  
<book category="Programming" Version="1.0">
    <title>Incide C#</title>
    <author>Tom Archer, Andrew Whitechapel</author>


  • Attributes are additional information attached to the elements start tag.

  • Example : the highlighted in yellow present attributes  

          <Book published-Year=“1999”>
              <Author> AAA</Author>

  • Attributes has the following rules :
1.    Must be enclosed between double quotations.
2.    Attributes name have the same rule of elements names.
3.    Elements can include unlimited number of attributes.
4.    We assign attributes to elements when we need an out-of-band attributes.