MCCC CIS 177 - Markup Languages

Create an XML Document

Introduction to XML

Overview of XML

XML (eXtensible Markup Language) allows you to specify structure and content of a document by breaking it into a series of elements. XML addresses the limitation of HTML in that HTML requires you to embed your content within presentation formats specified by HTML tags and cascading styles. This is a problem when you want the content of your page to change dynamically. XML separates document structure with format and allows you to create custom tags for specifying structure that describes the data, but not the format. Examine the following:

XML
HTML
<cdtitle>Kind of Blue</cdtitle>
<artist>Miles Davis</artist>
<contents>
     <track>So what (9:22)</track>
     <track>Freddie Freeloader (9:46)</track>
     <track>Blue in Green (5:37)</track>
     <track>All Blues (11.33)</track>
     <track>Flamenco Sketches (9:26)</track>
</contents>

<h2>Kind of Blue</h2>
<h3>Miles Davis</h3>
<ol>Tracks</ol>
     <li>So what (9:22)</li>
     <li>Freddie Freeloader (9:46)</li>
     <li>Blue in Green (5:37)</li>
     <li>All Blues (11.33)</li>
     <li>Flamenco Sketches (9:26)</li>
</ol>

 

XML has another advantage over HTML in that you can force a document to follow a specific structure by attaching a document type definition (DTD) or a schem to the document. Both DTDs and schemas define the rules for how data should be structured. In the above example, you can require the document include content about title, artist and tracks.

How XML Works

XML documents are text files and can be created in any text editor. After coding your XML document, you need a parser to interpret the document code. XML parsers are strict and will produce an error if you've omitted a tag, used an incorrect case or syntax. IE v. 5 above include MSXML as the parser.

Their are two categories of XML document: well-formed or valid. A well-formed XML document contains no syntax errors and complies with the W3C XML specifications. A valid document is a well-formed document that also complies with the rules specified in the DTD or schema. A parser that can verify a valid document is known as a validating parser. A parser that can verify only that a document is well-formed is known as a nonvalidating parser.

With XML, it is possible to create markup languages known as XML applications that work with specific types of documents by creating a defined set of tag names known as a vocabulary. Chemists use CML (Chemical Markup Language) that allows them to describe the chemical structure of a molecule. Mathematicians use MathML. Using a predefined vocabulary allows for cross-compatibility between different organizations, applications and systems. To use an XML application, you need the appropriate parser and a means to display the content in a useful format. For custom XML, you'll use styles to provide the display format.