Learn XML eXtensible Markup Language Pt 2

In this tutorial I’ll continue to cover XML and all of it’s capabilities. XML stands for eXtensible Markup Language. I hope you got this one point from the last XML Article. XML does one thing really well. It organizes and classifies your data, so that it is useable by a wide range of devices and software packages!

In this article I’ll explain how XML influenced HTML, to create the newest version of HTML called XHTML. I’ll then explain what well formed XML is and Document Type Definition’s (DTD).

Why Do we Need XHTML?

I wrote a whole article on the difference between HTML and XHTML. You may prefer to read that for a more in-depth discussion, but here I’ll cover all the most important points.

Why is XHTML now widely used? One simple reason. HTML provided people with the ability to display information in browsers. XHTML opened up the possibilities of providing content on many more internet output devices.

By using XHTML you will also find it easier to connect with databases and other structured data. And, because XHTML is highly structured you can better guarantee that your information will be displayed exactly the way you want it.

How to Turn HTML into XHTML

  • Every tag must have a closing tag
  • Tags that don’t have closing tags like <hr>, <br>, etc. must have a forward slash inserted in them like this: <hr /> and <br />.
  • All tags must be lowercase like this <p>, not like this <P>.
  • All tags must close in the right order. This is not legal <p> <h1> … </p> </h1>
  • If you assign a attribute, in a tag, the values must be surrounded by quotation marks.
  • Every XHTML file must have a valid DOCTYPE Declaration. Meaning instead of starting the page with <html>, it must start with <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

More on the DOCTYPE

Oh, bad things happen when you don’t define a DOCTYPE! If a browser doesn’t see a DOCTYPE defined, it will layout your website based on what is called Quirks Mode. This means your web page will look completely different on every browser and more than likely will look broken to anyone that visits your site.

In the DOCTYPE above you can see the words xhtml1-transitional.dtd. This signals to the browser that it should expect your web page to follow the rules described in that Document Type Definition. A DTD specifies what tags and attributes are allowed in your web page markup.

There are two possible DTD’s you can define in XHTML. If you are going to only style your pages with Cascading Style Sheets (CSS), use xhtml1-strict.dtd. If you may use HTML for presentation in anyway, stick with transitional.

Well-Formedness, Yes it’s a Word

Do you want your XML to be processed? If so your XML Markup must be what is called Well-Formed. That just means, it can’t violate any rules established in XML doctrine. If you do break any rules the XML processor while cease the processing of your XML Markup.

What Rules Must your XML Follow to Be Well-formed?

  • You need to include an opening XML declaration
  • You need to create a root element that will surround all of your other elements
  • Every element must have an opening and closing tag
  • Every empty element must end with a forward slash (/), just like I described with XHTML above.
  • All of your tags must be properly nested inside of each other just like XHTML.
  • All values assigned to attributes must be surrounded by quotes.

Document Type Definition’s (DTD)

You create a Document Type to define the rules that must be followed in your XML Markup. A DTD defines what elements are required and what attributes can be set and what their potential values can be. You are now entering the next level of XML Development!

Probably the most important question you can ask about DTD’s is, do you need one? If you are only creating small XML files, the answer is probably not. If however you are working with large sets of data that require very specific usage, the answer is probably yes.

DTD Jargon

Here is some jargon you must understand to get DTD’s:

  • XML Declaration: Every DTD must start with the line <?xml version=”1.0” encoding=”UTF-8” standalone=”no”?>. This tells the processor that this is an XML version 1.0 file. The character encoding used is of type UTF-8. And, that no external file is required for this document to work.
  • Elements Type: Defines the elements name and data type
  • Attribute List: Defines the element it is associated with, data type and all default values for all the attributes for the element
  • Entity Declaration: Entity’s help you eliminate repetitive information in your xml, by referencing data that can be found in an external location
  • Notation Declaration: Locates an external program that interprets data that an XML interpreter cannot.

That’s All Folks

In the next article I’ll completely describe how to create DTD’s. If you have any questions leave them below.

Till Next Time

-Think Tank

Leave a Reply

Your email address will not be published.