When I added HTML-code for the Creative Commons license on the bottom of this site, I noticed that my XHTML no longer validated. Like most of the sites I’ve built in the past, I used the XHTML 1.0 Transitional Document Type Definition (DTD). That turned out not to be a good choice as soon as I included the license code.

What are Creative Commons licenses?

Creative Common licenses provide an easy way to manage copyright terms. You choose what terms your work distributes under, and attach the proper license. The licenses are flexible, yet legal, and allow sharing material under your preferred terms. Head on over to their website to read more about the available licenses.

The offending HTML code

This is the offending code-snippet I got from the Creative Commons website for my site:

<span xmlns:dct="http://purl.org/dc/terms/" href="http://purl.org/dc/dcmitype/Text"
property="dct:title" rel="dct:type">Sitename</span>

The XHTML validator errors

If you’re somewhat familiar with HTML and XHTML, you might notice that this code uses some unusual markup. We can, for instance, see xmlns:dct, href, rel and property in the span tag. It is also included in other tags making up the whole markup for the license. As a result, the W3C Markup Validator gives the following errors:

Line 6, column 3116: there is no attribute “href”
…:dct=”http://purl.org/dc/terms/” href=”http://purl.org/dc/dcmitype/Text” prope…

Line 6, column 3160: there is no attribute “property”
…//purl.org/dc/dcmitype/Text” property=”dct:title” rel=”dct:type”>Make my kerne…

Line 6, column 3176: there is no attribute “rel”
…mitype/Text” property=”dct:title” rel=”dct:type”>Make my kernel</span> by <a x…

Solving the problem

To better understand the problem, I had to read up on what the code from Creative Commons actually means. It turns out that this piece of code is machine-readable meta data. It uses something called Resource Description Framework (RDF), which is a standard method for data interchange on the web. This makes it easy for “machines” to determine exactly how a specific work is licensed. It also allows search engines to scrape the works, including the license information.

And that’s a good thing!

So, to solve the original problem with invalid XHTML, I had to change the DTD to one that allows RDFa. Luckily, the World Wide Web Consortium (W3C) gives us a recommendation for using RDFa in XHTML. The following document type definition does the trick:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
                      "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">

This DTD can only appear after the optional XML declaration, and before the document body. So the markup can be rewritten like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
                      "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html version="XHTML+RDFa 1.0" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

In conclusion, this simple fix keeps the W3C Markup Validator happy. It keeps machines – like search engines – happy. And last but not least, it keeps me happy.

Espen Acklam Solberg

Espen Acklam Solberg is a system administrator with over 20 years of experience. He has worked in the telecom industry, in the aviation industry and for the government, managing critical infrastructure. His expertise lies in linux systems, virtualization, storage, backup, scripting and automation.He also runs his own print shop, producing branded merchandise for businesses and individuals, and is fond of gadgets and new technology.

This Post Has 3 Comments

  1. Victor

    sorry to disappoint.. but it still fails 🙁

    1. Espen A. Solberg

      Works for me, and this was exactly the way I did it on this site.

  2. takashi

    Works perfectly. A very good instruction. Thank you so much!

Leave a Reply