Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers

ArticlesThe Power of XML Syntax


March 1998 / Cover Story / Weaving a Better Web / The Power of XML Syntax

If you're familiar with HTML, you know that it has a fixed set of tags that control the appearance of information (things like font names, styles, and sizes). In other words, HTML describes the presentation of information. XML, on the other hand, should describe the data, rather than the formatting; an external style sheet should control a document 's appearance. Tags can be application-specific or they can be imported from a public Document Type Definition (DTD).

What all this means is that XML looks kind of like HTML, but its function is drastically different. The following example has tags for a bo ok's title, price, author, and so on, much like fields in a database.

<ORDER>
<SOLD-TO>
<PERSON><LASTNAME>Layman</ LASTNAME><FIRSTNAME>Andrew</FIRSTNAME>
</PERSON>
</SOLD-TO>
<SOLD-ON>19970317</SOLD-ON>
<ITEM>
<PRICE>5.95</PRICE>
<BOOK>
<TITLE>Number, the Language of Science</TITLE>
<AUTHOR>Dantzig, Tobias</AUTHOR>
</BOOK>
</ITEM>
<ITEM>
<PRICE>12.95</PRICE>
<BOOK>
<TITLE>Introduction to Objectivist Epistemology</TITLE>
<AUTHOR>Rand, Ayn</AUTHOR>
<ISBN>0-452-01030-6</ISBN>
</BOOK>
</ITEM>
<ITEM>
<PRICE>12.95</PRICE>
<RECORD><TITLE><COMPOSER>Tchaikovsky</COMPOSER>'s First Piano Concerto</TITLE>
<ARTIST>Janos</ARTIST>
</RECORD>
</ITEM>
<ITEM>
<PRICE>1.50</PRICE>
<COFFEE >
<SIZE>small</SIZE>
<STYLE>cafe macchiato</STYLE>
</COFFEE >
</ITEM>
</ORDER>

In addition to the fact that none of these tags describes what the data will look like when you view it (that's up to the DTD), there are two other notable differences between HTML and XML:

First, note that each tag has a matching end tag (HTML is more lenient about this). Note also how elements are nested -- an element may contain text and other elements, but elements may not overlap. XML calls anything that appears between an element's start and end tags the element's contents.

Second, XML documents should begin with a declaration of the XML version being used:

<?xml version="1.0"?>

This allows an XML "processor" -- a kind of parser -- to automatically recognize the version of a document it receives and reject versions it does not support. Unlike HTML browsers, which simply ignore syntax they don't understand, XML parsers can reject content.


Up to the Cover Story section contentsGo to previous article: The Power of XML SyntaxGo to next article: XML Namespaces
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network