XML Versus HTML

 <  Day Day Up  >  

Soon after XML emerged, there was speculation that XML would replace HTML. Many believed that because they were both descendants of SGML, XML was an upgrade. In reality, HTML and XML are designed for different purposes. HTML presents data, and XML describes the data. Both HTML and XML are important tools in the development of Web-based systems.

XML actually looks a lot like HTML. This is not surprising, because they come from the same source. However, XML provides two primary advantages that HTML does not ”validity and well- formed documents.

HTML tags are all predefined. Tags such as <HTML> , <HEAD> , <BODY> , and so on are all defined in the HTML specification. You cannot add your own tags. Because HTML is intended for formatting purposes, this is not really a problem. XML, however, is meant to define data. To define data, you need to create your own tag names . This is where a document called the Document Type Definition ( DTD ) comes into play. The DTD is where you define the tags that describe your data. When you create an XML document, you can only use tags that are predefined. All XML documents are checked for validity. The XML processor reads the DTD and determines whether the document is valid. If the document is not valid, a syntax error is produced.

Valid Documents

You are not required to use a DTD. However, using a DTD provides a great benefit to validating XML documents. XML only checks to see whether there is a well-formed document. You need to explicitly include a DTD to check for document validity. You define the parameters in the DTD.


For example, if you are creating a purchase order system, you might want to create a tag called <PurchaseOrder> in the DTD. If you then misspell the tag like this: <PurchasOrder> , the document will not be valid.

A validated document makes XML documents much more robust. For example, HTML has many tags that are part of a pair, such as <FONT> and </FONT> . If you were to forget to close the pair with the </FONT> tag, the browser will still load the document, but the results could be unpredictable. HTML will make a best guess and continue. XML, when used with a DTD, will not attempt a best guess. If the document is not constructed properly, an error will be generated and the document will not be valid.

Enforcing the validity of a document and ensuring that a document is well-formed provides industries with an important mechanism to share information.

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net