In order to figure out where XML should be used, you should bear in mind its key advantages. I briefly mentioned some of them earlier. This section takes an in-depth look at XML advantages over other mark-up languages or similar technologies.
When working with XML, people often forget the X stands for "Extensible." Extensibility means you can define any number of extra tags, without crashing the application. For instance, you can add children to this element:
<employee>
<name>John Doe</name>
<job>Software Analyst</job>
<salary>2000</salary>
</employee>
To make it look like this:
<employee> <name>John Doe</name> <job>Software Analyst <responsibility>Write technical specifications</responsibility> <responsibility>Translate client requirements into software requirements</responsibility> </job> <hire_date>Jun 25, 2005</hire_date> <salary>2000</salary> </employee>
The application reading this XML document will still understand which employee is referred.
Portability comes from the fact that you get to define the tags and attributes. No special libraries or application servers are required to "read" an XML document (although your development environment needs some configuring in order to become XML-aware, as I will explain in a future article). XML documents are plain-text files, hence they do not require a proprietary software to interpret them, as do most binary files. This means you can use Notepad to open and edit an XML file.
Therefore, XML is the choice, when information needs to be exchanged across several (incompatible) hardware or software platforms or applications. This has led to several applications of XML in communication technology, including the popular WML (Wireless Markup Language) and WAP (Wireless Application Protocol). WML is an XML-based language used to markup Internet applications for hand-held devices, such as phones or PDAs. To learn more about WML, you can read this tutorial from the W3 Consortium.
Portability also comes in handy in business-to-business applications, where many companies need to exchange a large amount of financial information in a platform-independent way. Different applications use SOAP (Simple Object Access Protocol), a popular XML-based protocol, to exchange such information over the Internet. These XML-based information sharing applications are called web services.
With XML, you can reduce the risk of content redundancy. Your clients will concentrate on using HTML and CSS for defining the layout and presentation, which will not be affected by any changes in the underlying information stored separately in an XML file.
For instance, a content management system might supply documents to end-users in a variety of formats: HTML, PDF, etc. However, there is no point in storing a separate version of each document for each format. The content would be duplicated and would take up valuable disk space, making the CMS clogged with redundant information and slower to use. Using an engine based on XML, the content can be stored only once and then extracted and displayed in the desired format.
Any processing or formatting requirements should be handled by a separate XSL (Extensible Style sheet Language) document. An XSL style sheet specifies the presentation of data contained by an XML file. XML and XSL are combined at output time to apply the required formatting to the data in the same way that Cascading Style Sheets (CSS) let you style HTML.
I will cover XSL in more detail in my next articles, and I will explain how to use the two together to produce formatted output for your application. Dreamweaver 8 offers you a quick, visual way to create your own XSL style sheets for a custom XML file. You’ll learn how simple it is to import an RSS feed in your site and provide your visitors with the latest news or updates.
If you look at the three important benefits of XML, you'll understand immediately where XML should be used:
Already XML is widely used to transfer data between different database applications. Most DBMS (including Microsoft Access or phpMyAdmin already allow exporting database tables as XML files.
RSS (Really Simple Syndication) is one of the most popular applications of XML. RSS is just another XML document format designed for syndicating news and news-like content. Popular websites that rely on RSS include community sites like Wired and Slashdot, or personal blogs. Macromedia makes its Developer Center articles available as an RSS feed. The main advantage of RSS is that you have people read your content in the format they want and import it in their own websites. I will show how to consume a RSS feed in one of my next articles, using Dreamweaver 8.
It's easy to figure out where you shouldn't use XML, just by looking at some of its disadvantages.