XML | Tags

XML tags are the important features of XML document. It is similar to HTML but XML is more flexible then HTML. It allows to create new tags (user defined tags). The first element of XML document is called root element. The simple XML document contain opening tag and closing tag. The XML tags are case sensitive i.e. <root> and <Root> both tags are different. The XML tags are used to define the scope of elements in XML document.

Property of XML Tags: There are many property of XML tags which are discussed below:

  • Every XML document must have a root tag which enclose the XML document. It is not necessary to name of root tag is root. The name of root tag is any possible tag name.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <root>
        <name>GeeksforGeeks</name>
        <address>
            <sector>142</sector>
            <location>Noida</location>
        </address>
    </root>

    chevron_right

    
    

  • The XML document must have start-tag, so first starting tag is known as root tag. The opening tag started with < bracket followed by tag name or element name and close with > bracket.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <Name>GeeksforGeeks
    <address>Noida

    chevron_right

    
    

  • The tag which is started by start tag must end with the same tag with forward slash (end tag), or in other words every XML document must be ended with end-tag. The end tag started with < followed by / and its pair tag name ended with >
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <Name>GeeksforGeeks</Name>
    <address>Noida<address>

    chevron_right

    
    

  • In XML, tags are case sensitive. It means that <Root> and <root> both are different tags.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <Name>Case sensitive</Name>
    <name>name and Name are different tag</name>

    chevron_right

    
    

  • The tag which contains no content are known as empty tags.
    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <name> </name>
    <address/>

    chevron_right

    
    

  • XML tag must be close in appropriate order. For example an XML tag opened inside another element must be closed before the outer element is closed.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <root>
        <name>GeeksforGeeks</name>
        <address>
            <add>Sector 142 Noida</add>
            <pin>201302</pin>
            <country>India</country>
        </address>
    </root>

    chevron_right

    
    




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.