Common-publishing-mistakes

From RDFaWiki

(Difference between revisions)
Jump to: navigation, search
(RDFa XHTML markup should be well formed)
m (@about Should Resolve to a URL: Fix relative URI resolution)
Line 52: Line 52:
</pre>
</pre>
-
The problem with the mark-up above is that the "Wesley Wyndham-Pryce" in the <tt>about</tt> attribute will be appended to the current page's URL. This is because the contents of the <tt>about</tt> attribute is supposed to either be a full URL or a relative URL. The RDFa parser will assume that "Wesley Wyndham-Pryce" is a relative URL. Therefore, if the web page was served from <tt><nowiki>'http://example.org/people.html'</nowiki></tt>, the subject will be <tt><nowiki>'http://example.org/people.htmlWesley Wyndham-Pryce'</nowiki></tt> (because the RDFa parser thought you were mentioning a relative URL).
+
The problem with the mark-up above is that the "Wesley Wyndham-Pryce" in the <tt>about</tt> attribute will be appended to the current page's URL. This is because the contents of the <tt>about</tt> attribute is supposed to either be a full URL or a relative URL. The RDFa parser will assume that "Wesley Wyndham-Pryce" is a relative URL. Therefore, if the web page was served from <tt><nowiki>'http://example.org/people.html'</nowiki></tt>, the subject will be <tt><nowiki>'http://example.org/Wesley%20Wyndham-Pryce'</nowiki></tt> (because the RDFa parser thought you were mentioning a relative URL).
The correct way to mark up the above example is this:
The correct way to mark up the above example is this:

Revision as of 19:36, 26 March 2009

Contents

Introduction

This page contains a number of RDFa publishing mistakes that web authors make when writing RDFa web pages. Please add to this page if you notice a common mistake that could be avoided.

Not Specifying the XHTML+RDFa DTD

In order to create a valid XHTML+RDFa document, you must specify the Document Type Definition (DTD) at the top of the document. The DTD is used by software tools to validate the structure of your document, without it the software must guess whether the document is HTML4, XHTML1.1, HTML5 or some other type of XML document. Without specifying the DTD, the software might guess incorrectly, so be a good Web citizen and specify the DTD at the top of your documents. This line MUST exist at the top of your XHTML+RDFa document:


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

Forgetting to Declare Prefix Mappings

At times, authors forget to declare prefix mappings. For example, you can't just use something like dcterms:title without first declaring the dcterms prefix mapping. If a prefix mapping isn't declared, the RDFa parser won't understand the prefix when it is used in your document. This will cause it to ignore some of your page data.

For example, this is wrong:


<div>
The title of this document is <span property="dcterms:title">Why RDFa is Awesome</span>.
</div>

You must specify the prefix mapping before using any prefix by utilizing the "xmlns:" attribute:


<div xmlns:dcterms="http://purl.org/dc/terms/">
The title of this document is <span property="dcterms:title">Why RDFa is Awesome</span>.
</div>

@about Should Resolve to a URL

Sometimes, authors have not understood that all RDFa subjects are URLs. This has caused them to do the following:


<div xmlns:foaf="http://xmlns.com/foaf/0.1/"
     about="Wesley Wyndham-Pryce" typeof="foaf:Person">
This paragraph is about <span property="foaf:name">Wesley</span>.
</div>

The problem with the mark-up above is that the "Wesley Wyndham-Pryce" in the about attribute will be appended to the current page's URL. This is because the contents of the about attribute is supposed to either be a full URL or a relative URL. The RDFa parser will assume that "Wesley Wyndham-Pryce" is a relative URL. Therefore, if the web page was served from 'http://example.org/people.html', the subject will be 'http://example.org/Wesley%20Wyndham-Pryce' (because the RDFa parser thought you were mentioning a relative URL).

The correct way to mark up the above example is this:


<div xmlns:foaf="http://xmlns.com/foaf/0.1/"
     about="#wesley-wyndham-pryce" typeof="foaf:Person">
This paragraph is about <span property="foaf:name">Wesley</span>.
</div>

This will ensure that the subject will be set to 'http://example.org/people.html#wesley-wyndham-pryce', which is a proper URL.

RDFa XHTML markup should be well formed

One of the most common publishing problems is invalid xhtml, this is not just true for RDFa Documents but many other X/HTML Documents too. RDFa xhtml documents should be well formed (valid) If a document is not well formed then parsers may have difficulty producing the correct output due to the tidying process involved "repairing" the markup. If a parser does not support a tidying process (which is true for most of the existing xslt based parsers) then the author is likely to expect no RDF output at all.