Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

XML Elements

XML elements are represented by tags. Elements usually consist of an opening tag and a closing tag, but they can consist of just one tag. Opening tags consist of <, followed by the element name, and ending with >. Closing tags are the same but have a forward slash inserted between the less than symbol and the element name.

Example:

<tag>Data</tag>

Empty elements are closed by inserting a forward slash before the greater than symbol.

Example of empty tag:

<tag />

The following syntax rules are important to note, especially if you're used to working with HTML where you don't usually need to worry about these rules.

All Elements Must Be Closed Properly

If you're familiar with HTML, you will know that some HTML tags don't need to be closed. In XML however, you must close all tags. This is usually done in the form of a closing tag where you repeat the opening tag, but place a forward slash before the element name (i.e. </child>). If you are using an empty element (i.e. one with no closing tag), you need to place a forward slash before the greater than symbol at the end of the tag (i.e. <child />).

Example for opening/closing tags:

<child>Data</child>

Example for empty elements:

<child attribute="value" />

Tags Are Case Sensitive

All tags must be written using the correct case. XML sees <tutorial> as a different tag to <Tutorial>

Wrong:

<Tutorial>XML</tutorial>

Right:

<Tutorial>XML</Tutorial>
<tutorial>XML</tutorial>
<TUTORIAL>XML</TUTORIAL>

Elements Must Be Nested Properly

You can place elements inside other elements but you need to ensure each element's closing tag doesn't overlap with any other tags.

Wrong:

<tutorial>
  <name>XML</tutorial>
</name>

Right:

<tutorial>
  <name>XML</name>
</tutorial>

Element Names

You can use any name you like for your elements as long as they adhere to the following rules:

  • Element names can contain any character (including letters and numbers)
  • Element names must not contain spaces
  • Element names must not begin with a number or punctuation character (for example a comma or semi-colon etc)
  • Element names must not start with the letters xml (whether lowercase, uppercase, or mixed case)

You should using a colon (:) in your element names, as this is reserved for another purpose.

Enjoy this website?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com