Feedback

  • Contents
 

Comparing XML to HTML

XML and HTML are both markup languages, and they both use syntax that is enclosed between angle-bracketed tags. But they are used for different purposes—almost as if one is an apple and the other is an automobile.

XML is used to define data in a highly structured way, so that it can be read both by people and by computers. If you send an XML document to a computer that understands its format, the computer can parse the document and make use of all of its data. To achieve this goal, XML documents must be well-formed and valid, or the receiving computer will not be able to process them. Note, however, that the XML formatting of a document is not directly responsible for the appearance of this data.

HTML, on the other hand, is used to render documents in a web browser, so people can read them. That is, it controls the appearance of the document. One of the consequences of this is that an HTML rendering engine will do whatever it can to render a document that isn't well-formed, so that the person who opened it can read the document.

While any given version of HTML supports a fixed set of tags, XML is completely extensible. As long as your document is well-formed—and as long it follows an XML Schema that is understood by the parser at the other end—you can make up tags for just about any purpose you can think of, whether it's a row in a table, a financial transaction, a short story, or an object that exposes methods and properties.

And if you need to render an XML document, you can use XSLT (eXtensible Stylesheet Language Transformations) to transform all or part of it into another type of document, reordering the data as needed. If your target document type is HTML—or any other other form of presentation-oriented markup—you can format the output in just about any way you could imagine.

Other features of XML

  • Because XML is plain text, it is easily transmitted between computers and through firewalls.

  • XML is more secure than binary files, since text files can't be executed directly.

  • XML is universally compatible, as the XML file format is not tied to any particular program, operating system, database, or network. This also means that XML can be used by non-web applications to store data.