How can XML help my web site?
"Our site needs to be done in XML" is a line we've heard several times. Our
response to that statement is usually something along the lines of, "Sorry, but
that won't work." This answer usually gets the client’s attention. We are then
asked why we can’t do their site in XML. Simple, XML doesn’t replace HTML.
This idea is a very common misperception about XML, and understandably so. You
always hear people talking about how XML is the next great thing for the web.
And heck, the two acronyms sound a lot alike, and even when spelled out, they
sound related; Hyper Text Markup Language and Extensible Markup Language (XML
just sounds better than EML). But the truth is that XML is not a replacement
for HTML, but rather a compliment to it.
Extensible Markup Language is really just a way of defining data, any data.
Let’s say you have a phonebook and you want to enter all of the data into a
format that could be easily displayed, searched, reformatted, or converted.
Well, XML would be the way to go. Now, we’ll pretend that you sell go-carts and
replacement parts. You want to categorize every last part used in the street
racer. An XML file could know that the chain guard is part of the chain
assembly, which is part of the street racer. The file would also know the cost
of the part and the estimated service time for the replacement. XML truly has
no boundaries for defining data.
How does XML work? Frankly, it works however you want it to work. A standard
convention was agreed upon by some of the largest technology companies in the
world. The convention describes “Elements” and “Attributes.” With our go-cart
example above, each part would be an element. An attribute, or detail of the
part element would be its name; for instance, the chain guard. Other attributes
would be the part number, the part cost and the time for replacement. With the
same example, each small assembly, such as the chain assembly, would be another
element. The assembly elements would contain part elements, in a hierarchal
manner. Getting the picture?
Maybe you need to see an example. Let’s stick with the go-cart theme.
This could be a section of a go-cart XML file.
Looks pretty straightforward, doesn’t it? But what happens when we want to add
another assembly to the file?
Well, that’s when we take the next hierarchal step.
Again, pretty simple. Now that you see how XML files are laid out, you are
probably wondering what a go-cart has to do with your web site. Well, not much.
But, the design of a go-cart XML file has a lot to do with your web site. Think
of each page on your site as a part. Now, each page probably belongs to a
section, or an assembly. And when you put all of the sections together, you get
your site. Now it’s starting to all come together.
Here’s a simple example of how a site could be laid out.
So, now that we understand what XML is and how data can be defined, let’s learn
a little about why it should be used. In a nutshell, XML files make it very
easy to make changes. If you store data for your website in XML, you can do
whatever you want with it. You could take the site layout above and create a
toolbar in any format you want. Or you could create a site map page, or even
create a tool to track hits on each page. Now that we have the data in a format
that is easy to understand, we can do whatever we want with it. But most
importantly, by using XML files, you are now able to remove the data from the
programming code. The code will now be independent from what pages you want to
have in your toolbar. This allows you to make changes in one file and have it
change the way your toolbar is displayed on every page in your site. Now, that
is just cool!
Jeff Handley