(Extensible Markup Language)

What is XML?

-XML is a way of creating structured documents.

-XML uses tags and elements to organize and structure a document.

-XML also allows nesting of elements.

Shown below is an example XML text:

<?xml version = “1.0?”?>
<motorvehicles>  
	<vehicle>
		<registration_no>CBB1456</registration_no>
		<make>Toyota</make>      
		<model>Premio</model>  
	</vehicle>  
	<owner>      
		<first_name>Amal</first_name>      
		<last_name>Perera</last_name>      
		<nic>900324770V</nic>  
	</owner>
</motorvehicles>

In the above XML text, <motorvehicles> is the top level element. There must be a top level element in all XML documents.

<vehicle> is a starting tag and </vehicle> is an ending tag. Sandwiched between the starting and ending tags, we can have either data in text format or nested tags. <registration_no>,<make>, and <model> are elements nested under <vehicle> tag.

Unstructured text can also be contained mixed among XML elements. However, this can cause confusion and is discouraged for data representation.

Shown below is an example of unstructured text mixed with XML elements.

<?xml version = “1.0?”?>
<motorvehicles>  
<vehicle>  
	This vehicle is a car.      
	<registration_no>CBB1456</registration_no>      
	<make>Toyota</make>      
	<model>Premio</model>  
</vehicle>  
<owner>      
	<first_name>Amal</first_name>      
	<last_name>Perera</last_name>      
	<nic>900324770V</nic>  
</owner>
</motorvehicles>

The text "This is a car" in the above example is mixed with XML elements.

XML elements can contain one or more attributes as well. For example, the below XML segment demonstrates <vehicle> element having two attributes, namely, "type" and "year".