[ Team LiB ] Previous Section Next Section

Hour 19. Creating an XML Application

What You'll Learn in This Hour:

  • What XML is and why it is useful

  • How to generate XML from a JSP or a servlet

  • How to use XSL to transform XML

  • How to use JSTL's XML tags

The Extensible Markup Language (XML) represents an important step in data representation. In the past, programs used many different formats for storing data. There have been text files with comma-delimited or pipe-delimited fields, binary files in any number of formats, and even plain ASCII text. Unfortunately, most programs use slightly different ways to store data, even if the overall format is similar. For example, when you save data in comma-separated fields, how do you specify what each field is? You might save the first name followed by the last name. Another developer might save the last name and then the first name. How do you know the format of the file unless someone tells you? You could put a line at the top of the file explaining what each field is, but even that might have different formats.

Another problem you encounter when storing data is that most representations tend to be tabular in nature. That is, when you write data into a file, you typically put all the information for a particular data element on a single line in the file. What happens when the data you want to write is a Java object with many nested data structures? How can you store all those data structures within a single line, especially if you must stick to a prescribed set of fields?

XML solves this problem by defining a standard way to represent data, a standard way to tag the data with its type, and a standard way to describe the overall data structure. (There isn't room to cover XML in its entirety here. You can learn more about XML from Sams Teach Yourself XML in 21 Days, 3rd edition, by Steve Holzner, ISBN: 0672325764.) XML is very simple, easy to read, and easy to understand. There are a few things XML is not:

  • XML is not a replacement for HTML. Although there is an XML-compliant version of HTML, XML does not define how to represent data on a Web browser.

  • XML is not a cure for all the data format ills. Various software vendors and the business sector must still agree on a common representation for data. For example, the travel industry needs a standard format to represent a reservation. The banking industry needs a standard format to represent account information.

  • XML is not a programming language. XML lets you describe data, but it doesn't let you describe how to process the data.

    [ Team LiB ] Previous Section Next Section