XML How to use

XML mainly used in software and web development. It used to store data and transform it. More often it used to keep data separated from the HTML or Display.

XML Separates data from HTML or Presentation

XML does not used in anyways to display or present your data.

Single XML file you can use to display data in various ways into HTML page

XML is used as intermediate format to exchange data between system and desired output.

XML stored in separate file or in database also.

HTML file doesn’t need to be edited when you change any data into your XML file.

To display XML data in HTML or web page, you must need to write java scrip or VB script. You can also read and display data through any programming languages like PHP, C#, VB.NET.

Lets understand with below example;

<?xml version="1.0" encoding="UTF-8"?>
<products>
<product>
<name>Sony Xperia R1 Dual</name>
<color>Silver</color>
<price>$650.00</price>
<discount>$20.00</discount>
</product>
<product>
<name>Apple iPhone 8S</name>
<color>Red</color>
<price>$950.00</price>
<discount>$30.00</discount>
</product>
<product>
<name>Sony Xperia R2 Dual</name>
<color>White</color>
<price>$750.00</price>
<discount>$10.00</discount>
</product>
<product>
<name>Apple iPhone 9S</name>
<color>White</color>
<price>$999.00</price>
<discount>$50.00</discount>
</product>
</products>

In above example, you can see how 5 products details structured into XML format. Here, you can define your own tag as earlier explained in first chapter. Now, let’s look how we can format these data into HTML format. We can use HTML and Java Script to read XML data and displayed into following format. Here, you can display XM data into any HTML format you wish.

Product NameColorPriceDiscount
Sony Xperia R1 DualSilver$650.00$20.00
Apple iPhone 8SRed$950.00$30.00
Sony Xperia R2 DualWhite$750.00$10.00
Apple iPhone 9SWhite$999.00$50.00

Many XML format exists in different industry to describe their data. For example

News Information
Fashion and Clothes Information
Health Information
Real Estate Information
Finance Information
Stock Market Information
Information Technologies

Let’s review the example with XML format and sample data for Stock Market industry.

<?xml version="1.0" encoding="UTF-8"?>
<market>
<head>
<title>USA Stock Market</title>
</head>
<stocks>
<stock>
<symbol>GOOG</symbol>
<current_price>$120.00</current_price>
<today_low>$100.00</today_low>
<today_high>$130.00</today_high>
</stock>
<stock>
<symbol>GOOG</symbol>
<current_price>$120.00</current_price>
<today_low>$100.00</today_low>
<today_high>$130.00</today_high>
</stock>
</stocks>
</market>