Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

End Tag

The end tag functions exactly like a right parenthesis or a closing quotation mark or a right curly brace. It contains no data of its own; it simply ends the most recent (innermost) tag with the same name.

XML requires a matching end tag for each start tag. Not only must they have matching names, but they must also nest properly. The most recently encountered start tag must be paired with the next end tag. If they do not match, it is a fatal error.


The end tag contains exactly the same name as the start tag it closes. Simple punctuation distinguishes it from the start tag:



It cannot include attribute assignments or any other content.


Each end tag must have

  • the </ character pair

  • the name

  • the > character

Alternatively, in the special case of an empty element, the end tag may be fused with the start tag. This results in an empty tag containing

  • the < character

  • the name

  • optional attribute assignments

  • the /> character pair

Examples of End Tags

<Team> . . . </Team>

Street, city, etc.

<Team> . . . <Player> . . .

</Player> . . . </Team>-

Proper nesting


<Play> </Play>

Empty Play element


Exactly equivalent to the preceding, using an empty tag

<Play speed= "normal"/>

Empty Play element with speed attribute

<A><B> . . . <C/> <C/><B> . . .

Complex nesting: A contains only B, which


contains data, two empty Cs, and another B. This inner B also has data and a single empty C. All three Cs are equivalent.

Bad Examples


Not a match (case violation)

<Team/>. . . </Team>

<Team> . . . <Player> . . .

End tag paired with self-ending empty start tag


</Team> </Player>

Bad nesting

  • + Share This
  • 🔖 Save To Your Account