What is XML?

xml logoWhat is XML? XML is an abbreviation for Extensible Markup Language. It is widespread in software and hardware development as a data description format.
XML was designed to describe data and to carry information. Information written with the help of XML can be easily read and understood both by people and computers.  XML files have .xml extension and can be opened with any text editor or browser.

How the information at XML file is organized?

Data at the XML file is structured by tags. Tags are the keywords assigned to a piece of information. An XML tag is composed of the name of the element, surrounded by angle brackets. Noteworthy that in XML there are no predefined tags, so you can create any you want. Information you want to place in your XML document has to be surrounded by opening and closing tags:

<name> Bob </name>

Note that the name of your closing tag has to be the same as opening one. Keep in mind that XML also is a case-sensitive language.
Let’s imagine that we have to describe our friends. How to do that with XML?
First, we define the XML version:

<?xml version="1.0" encoding="UTF-8"?>

Second, we create a root tag that will keep all our data together as:

<?xml version="1.0" encoding="UTF-8"?>
<FRIENDSLIST>
</FRIENDSLIST>

XML documents form a tree structure with root and child elements. The first root element is mandatory. The rest elements optional can have sub-elements.
And third, we are going to add our friends’ info to the document:

<?xml version="1.0" encoding="UTF-8"?>
<FRIENDSLIST>												
    <FRIEND>													
        <NAME> Bob </NAME>											
        <AGE> 25 </AGE>									
    </FRIEND>												
    <FRIEND>
        <NAME> Catherine </NAME>
        <AGE> 23 </AGE>
    </FRIEND>
    <FRIEND>
        <NAME> Mark </NAME>
        <AGE> 27 </AGE>
    </FRIEND>
</FRIENDSLIST>

But that is not all. Description info can be also given to the tag itself as an attribute (in this example – the “id” attribute of a FRIEND tag):

<FRIEND id=”2”> 
    <NAME> Catherine </NAME> 
    <AGE> 23 </AGE> 
</FRIEND>

There is no rule when to put down data as tag element or tag attribute. But usually attributes are used to comprise data related to a specific element.
These are the essentials you need to understand what XML is.

 

by Aliona Khomyk

Leave a Reply

Be the First to Comment!