XML Tags and Syntax

XML tags are user-defined. See the example below:

<?xml version="1.0" encoding="UTF-8”?>
<book>
    <title>Great Stories for Children</title>
    <author>Ruskin Bond</author>
    <info>This book is for children.</info>
    <body>It is a collection of author's most delightful children's stories​.</body>
</book>

The book above is quite self descriptive. It has title and author information, it also has info and a body. All the tags above are related to a book and that’s why they are embedded within <book> and </book> tags. But still, this XML document does not do anything. It is just pure information wrapped in tags. The tags in the example above (like The tags in the example above (like <title> and <author>) are not defined in any XML standard. These tags are to be invented by the author of the XML document.

That is because the XML language has no predefined tags. Whereas the tags used in HTML (and the structure of HTML) are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.). XML allows the authors to define their own tags and their own document structure.​

The root element book can be preceded by an optional (for XML 1.0 only) XML declaration element stating what XML version is in use (normally 1.0); it might also contain character encoding and external dependencies information. Starting with XML version 1.1, this declaration becomes mandatory. This is necessary as an XML document without an XML declaration is assumed to be a version 1.0 document.​ The specification requires that processors of XML support the pan-Unicode character encodings UTF-8 and UTF-16 (UTF-32 is not mandatory).

 

Differences between XML and HTML

XML is a markup language much like HTML. But they serve different purposes. HTML was designed to format and display data, with focus on how data looks. Whereas XML was designed to transport and store data, not to display data. Therefore HTML is about displaying information, while XML is about carrying information.

XML tags are not predefined. We must define our own tags. XML is designed to be self-descriptive and it is a W3C Recommendation. XML is just plain text. Software that can handle plain text can also handle XML. However, XML-aware applications can handle the XML tags specially. The functional meaning of the tags depends on the nature of the application.

Their differences are given below:

XML

HTML

 1) XML was designed to transport and  store data, with focus on what data is.

 1) HTML was designed to display data,  with focus on how data looks.

 2) XML is about carrying information.

 2) HTML is about displaying information.

 3) XML tags are not pre-defined in any XML standard. XML allows the authors to define their own tags and own document structure.

 3) HTML tags are predefined. The HTML documents can only use tags defined in the HTML standard (e.g., <html>, <head>, <body>, <p>, <h1> etc.).

 4) XML allows the data storage (defined according to DTD or Schema) and data retrieval from XML documents.

 4) HTML is used only for presentation purposes, so we can not retrieve      information from HTML documents.