XML Elements




XML Elements

  • XML elements are represented by tags. Xml elements behave as a container to store all the text, other elements, attributes and all media objects.
  • There is no limitation to use elements in Xml.
  • Elements usually consist of an opening tag and a closing tag, but they are consider as a single 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.

Syntax

<tag>Data</tag>
  • Empty elements doesn’t have the closing tag. They are closed by inserting a forward slash before the greater than symbol.

Syntax for Empty Element

<tag/>
XML Elements

Learn XML - XML tutorial - XML Elements - XML examples - XML programs

XML Elements Rules

  • All the XML elements must have closing tag:
    • In HTML some tags don't need to be closed.
    • In XML however, you must close all tags except empty tag.
    • The opening and closing tags must be similar except the closing tag contains a forward slash before the element name.

Example for opening/closing tags

<child>Data</child>

Example for empty elements

<child attribute="value" />
  • The XML elements are case sensitive:
    • All tags must be written using the correct case. XML sees <tutorial> as a different tag to <Tutorial>
 Elements are Case Sensitive

Learn XML - XML tutorial - Elements are Case Sensitive - XML examples - XML programs

  • XML Elements Must Be Nested Properly
    • You can place elements inside other elements but you need to ensure each.
 Elements Nested Properly

Learn XML - XML tutorial - Elements Nested Properly - XML examples - XML programs

  • XML Element Naming 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)
    • Element names shouldn’t use a colon (:) because colon is reserved for another purpose.


Related Searches to XML Elements