XML & DTDs
Computing Resources >> Tutorials >> Web Development >> XML & DTDs  

Introduction and Objectives

XML Anatomy

Creating a Simple XML Document

"Well Formed" vs. Valid

Is Your Markup Well-Formed?

Creating a DTD

Validating with a DTD

XML Resources

Evaluate this tutorial

Is Your Markup Well-Formed?

So now that we've created some XML documents, we want to make sure they are well formed documents. To determine whether or not XML documents are well formed, we need to use an XML parser.

Programs such as Dreamweaver or Cooktop have XML parsers built into the software application, but you can also check for well formed XML with most Internet browsers. The most recent versions of Internet Explorer, Netscape, Mozilla or Firefox have at least some simple XML parsing functionality built in and can check XML documents for well formed markup.

Each parser can have different error messages for the same mistake, but the most common errors are not having closing tags, element names not matching up, not closing quotation marks for attributes, and incorrect order.

Since XML requires elements to have opening and closing tags, missing a closing tag will cause what XML calls a "fatal" error - the parser will shut down and give an error message.

To see what message you might get with different parsers for this error, use this modified email XML document. You will see the error message that your browser generates. To see the code, go ahead and view the source (from your browser menu, choose View > Source or Page Source, depending on the browser). Notice that the <sender> element is missing a closing tag.

When creating elements, you can use a mixture of characters, both upper and lower case, as well as symbols and numbers. However, XML is less forgiving then HTML; in XML, case matters. For example, <sender> and <Sender> are two separate types of elements. HTML would read them as the same element. So another common error when coding in XML is accidentally mixing cases between opening and closing tags. Take a look at this example of mixed capitalization to see what error messages your parser might give for that mistake. To see the code that generated this error message, view the source.

Another common error is forgetting to close your quotations around the attributes value. Take a look at this example of forgetting to close quotations to see what error messages the parser you're using might give. To see the code that generated this error message, view the source.

Finally, XML parsers expect to see tags opened and closed in a certain order. XML requires the most recently opened XML element to be closed. One way to remember this is the ABBA rule. No, we're not talking about the "Dancing Queen"; rather, if element A is opened first, and element B is the child of element A, you must close element B before closing A. Here's what it looks like:

<A>

<B>
</B>
</A>

For an example of the error messages this mistake might generate, look at this example of order error in XML. To see the code that generated this error message, view the source.

These are some of the common errors that are seen when making sure that your XML is "well formed." Now let's talk about DTDs and validating your XML documents.

 
next section >

 

Watch the video
screenshot
Choose format/speed:

real media dial-up | broadband
real media dial-up | broadband

Entire tutorial (with captions)
real
media dial-up | broadband
windows media dial-up | broadband

Flash version of tutorial
segment | entire

html transcript

© 2004 Jacob Cleary | iSchool | UT Austin | webmaster