What are XML elements?

3 Apr 2018

What are XML elements?


Most documents that you encounter, for example books and magazines are broken down into components such as chapters and articles. These can be broken down into smaller components, for example, titles, sections, paragraphs, figures, tables and so forth. And again, these can be broken down into smaller components again, such as sentences and individual words.

Every document can be viewed this way, in that a complete document is the sum of its individual components. In XML, these individual components are called elements. An XML element is everything from and including the element’s start tag, up to and including the element’s end tag. Each element represents some logical component of a document.

The rules for elements are as follows. An element can contain:

  • text
  • attributes
  • other elements
  • or a mix of the above

The root element

The first element in the document is called the root element, also known as the document element. All other elements in the document are nested into the root element. All XML documents begin with one root element and the root element cannot exist anywhere else in the document.

Nested elements are elements that are contained within other elements.

An example of a root element and it’s associated nested elements is shown here.


<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<body>Don’t forget our meeting today at 2pm</body>



In this example, <note> is the root element of the document. As we can see, the elements <to>, <from>, <heading> and <body> are all contained or nested within the root element <note>.

An element that is contained or nested within another element is called a child element and the element containing the child element is known as the parent element.

All elements within the root element must nest properly.  This means that each child element must close before its parent closes.

Leave a Reply