Some of the advantages of XML are:
- Domain-specific vocabulary
- Data interchange
- Smart searches
- Granular updates
- Users-selected view of data
- Message transformation
Domain - Specific Vocabulary
HTML uses a set of predefined tags to present data in various formats. While working with HTML, you are restricted to the use of only these tags. On the other hand, XML does not have any predefined tags. You can create new tags based on the requirerments of the application, that is, you can create domain-specific vocabulary in XML.Consider the following HTML code snippet:
<B> My Book </B>
<p>
john smith <br>
Tech books publications <br>
$30.00<br>
</p>
The preceding code snippet represents information about the author, publisher, and cost of a book. However, the tags used for presenting this content do not reveal this information. The tags specify the format in which the content must be displayed on a browser. The same information can be represented in XML as:
<Book>
<NAME> My Book </NAME>
<AUTHOR> John smith </ AUTHOR>
<PUBLISHER> tech books publications </PUBLISHER>
<PRICE>$30.00</PRICE>
</BOOK>
In the preceding code snippet, the content is described by using meaningful tags to represent the data. XML enables you ti create a markup language for your application and does not place any restriction on the number of tags that you can define. There are several languages derived from XML, such as MathML, which is a markup language used for the representation of mathematical formulae and scientific data, and Wireless Markup Language(WML), which is used for Web Applications that can be accessed by using a cellular phone.
Data Interchange
Data interchange is essential to carry out business transactions. You need to establish standard interfaces among related enterprises in which the data is stored is disparate forms to facilitate data interchange. XML produces files that are unambiguous, easy to generate, and easy to read. It provides a structure to store data in textual format, which can then be used as a standard format or protocol for data interchange. This eliminates the differences in the system that exchange data.Smart Searches
Although HTML provides you with a set of predefined tags, it is difficult to implement a search on an HTML document. for example, consider the following code snippet in HTML :The best picture award in 1999 went to the film <b> Titanic. </b> This film was based on the story of a ship called <b> Titanic.</b>
In the preceding code snippet, the search engine will not be able to determine whether you are referring to Titanic as a ship, a play, or a film. If you specify a search for the next Titanic within the tags <b> </b>, then the search will return all the words matching Titanic within the <b> and </b> tags.
The flexibility to create user-defined tags in XML enables you to create smart search engines. For example, consider the following code snippet:
The best picture award in 1999 went to the film
<FILM> Titanic.</FILM>
This film was based on the story of a ship called.
<SHIP>Titanic.</SHIP>
In the preceding code snippet, it is very clear that Titanic is a reference to a film by that name. When you perform a search, you can specify that the search needs to be performed for the text Titanic within the <FILM> and </FILM> tags. This enables the browser to perform a focused search and return precise information that matches the search query.
Granular Updates
Document updates in HTML are slow as the entire document needs to be refreshed from the server. In comparison with this, only the changed content needs to be downloaded in XML documents, thus making updates faster. For example, if you need to update stock prices on a Web page, it will take more time to update an HTML document, as the entire page would have to be reloaded. With XML, only the prices can be updated.User -Selected View of Data
In HTML, you need to create separate HTML pages to display the same information in different formats. This is because an HTML page contains data, as well as, instructions to the browser for the presentation of data. On the other hand, XML concentrates on the data and not on its presentation. You can display XML document in the required format by using Cascading Style Sheets(CSS) and Extensible Style Sheet Language (XSL). This separation of data from its presentation has various advantages. For example, you can download an XMl document once and reply different formatting styles by using CSS or XSL.A user can select one, several, or all records, and sort by different attributes, format data based on a condition, or switch to the graphical view without requesting the XML document from the server for each operation. The same data can be presented differently, perhaps as a subset, depending on the viewer's role with respect to the data. For example, the account department my be able to access financial information, whereas a buyer may not be able to access the same information.
HTML does not allow conditional formatting of a document. For example, it is not possible using HTML to display the name of the product with the highest sales figure in green and the lowest sale figure is red. You can implement conditional formatting of data by using XML.