Let us learn about one of the most important part of XML, the XML tags. XML tags form the foundation of XML. They define the scope of an element in XML. They can also be used to insert comments, declare settings required for parsing the environment, and to insert special instructions.
We can broadly categorize XML tags as follows −
The beginning of every non-empty XML element is marked by a start-tag. Following is an example of start-tag −
Every element that has a start tag should end with an end-tag. Following is an example of end-tag −
Note, that the end tags include a solidus ("/") before the name of an element.
The text that appears between start-tag and end-tag is called content. An element which has no content is termed as empty. An empty element can be represented in two ways as follows −
A start-tag immediately followed by an end-tag as shown below −
A complete empty-element tag is as shown below −
Empty-element tags may be used for any element which has no content.
Following are the rules that need to be followed to use XML tags −
XML tags are case-sensitive. Following line of code is an example of wrong syntax </Address>, because of the case difference in two tags, which is treated as erroneous syntax in XML.
<address>This is wrong syntax</Address>
Following code shows a correct way, where we use the same case to name the start and the end tag.
<address>This is correct syntax</address>
XML tags must be closed in an appropriate order, i.e., an XML tag opened inside another element must be closed before the outer element is closed. For example −
<outer_element> <internal_element> This tag is closed before the outer_element </internal_element> </outer_element>