How Can XML be Used?

XML is used in many aspects of web development.

XML is often used to separate data from presentation.

XML Separates Data from Presentation

XML does not carry any information about how to be displayed.

The same XML data can be used in many different presentation scenarios.

Because of this, with XML, there is a full separation between data and presentation.

XML is Often a Complement to HTML

In many HTML applications, XML is used to store or transport data, while HTML is used to format and display the same data.

XML Separates Data from HTML

When displaying data in HTML, you should not have to edit the HTML file when the data changes.

With XML, the data can be stored in separate XML files.

With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.


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

  <book category="cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>

  <book category="children">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>

  <book category="web">
    <title lang="en">XQuery Kick Start</title>
    <author>James McGovern</author>
    <author>Per Bothner</author>
    <author>Kurt Cagle</author>
    <author>James Linn</author>
    <author>Vaidyanathan Nagarajan</author>

  <book category="web" cover="paperback">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>


You will learn a lot more about using XML and JavaScript in the DOM section of this tutorial.

Transaction Data

Thousands of XML formats exists, in many different industries, to describe day-to-day data transactions:

  • Stocks and Shares
  • Financial transactions
  • Medical data
  • Mathematical data
  • Scientific measurements
  • News information
  • Weather services

Example: XML News

XMLNews is a specification for exchanging news and other information.

Using a standard makes it easier for both news producers and news consumers to produce, receive, and archive any kind of news information across different hardware, software, and programming languages.

An example XMLNews document:

<?xml version="1.0" encoding="UTF-8"?>
    <title>Colombia Earthquake</title>
      <hl1>143 Dead in Colombia Earthquake</hl1>
      <bytag>By Jared Kotler, Associated Press Writer</bytag>
      <location>Bogota, Colombia</location>
      <date>Monday January 25 1999 7:28 ET</date>

Example: XML Weather Service

An XML national weather service from NOAA (National Oceanic and Atmospheric Administration):

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

<credit>NOAA's National Weather Service</credit>

  <title>NOAA's National Weather Service</title>

<location>New York/John F. Kennedy Intl Airport, NY</location>
<observation_time_rfc822>Mon, 11 Feb 2008 06:51:00 -0500 EST

<weather>A Few Clouds</weather>