Skip to content

An introduction to XML

This section covers:

What is XML

  • 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 is designed to be very descriptive
  • XML is a W3C Recommendation

Snippet of XML:

   <note to="Alice" from="Bob">
      <body>Don't forget to buy milk!</body>

This example contains one parent element, a note element. This element is started with the opening note tag. It has meta information that is described through the use of attributes. This note element has two attributes: to and from. The note element has two child elements: subject and body. These elements don't have any attributes but do have some text content.


Like HTML, XML uses tags to open and close elements.

Unlike HTML, all tags in XML MUST be closed with either a closing tag:


Or self closing:

   <tag attribute="value"/>


An XML element is everything from (and including) the element's start tag to (and including) the elements end tag.

An element can contain:

  • Other elements (children)
  • Attributes
  • Text
  • Or a mix of all of the above...


Attributes provide additional pieces of information about the information being stored in the XML.

The attributes in the note example above show the to and from recipients of the note, whereas the actual text of the subject and the body are child elements.

Entity references

XML has a couple of character limitations.

If you need to use any of the following characters within an element you must use the entity reference alternative:

Character/Symbol Entity Reference Description
< < Less than
& & Ampersand

For example if Alice's message to Bob was to 'get milk & bread', then it would be need to written as:

   <body>Don't forget to buy milk &amp; bread!</body>


Comments can be added into XML using the following syntax:

   <!-- Comments can be added into xml files using this syntax. -->


Comments cannot include other comments (nested comments) nor can comments contain double dashes '--'.

More info

For more info on XML visit: W3Schools