advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
advertisement
Rate this item | 0 users have rated this item.
 

Writing Functional Code with RDFa

RDFa is a current W3C Candidate Recommendation, and large organizations such as Yahoo! are implementing RDF in their search engine technologies. Now is an excellent time to learn how to use this set of XHTML extensions to produce RSS news feeds. 


advertisement
ews feeds in all their manifestations—both with and without RDF—have a long tradition as structured data on the web. RDF—the data model—can state relations between certain entities. For example, one relation between a human and a feed could be conceived as creator.

In contrast, HTML is about structure and presentation, the semantics of the conveyed data is not—and cannot—be represented. Presentation-oriented formats such as HTML are useful for users, but typically cause rather expensive back-end processing (along with heuristics).

However, the RDF data model is useless without serialization syntaxes that are available to exchange representations online. To date, RDF/XML is the only official RDF serialization syntax that is available for developers to use.

Unfortunately, this means that it is not feasible to use RDF—even RDF/XML—in HTML. That is an ongoing issue. RDF serialization needs to make a persistent graph structure (be it in XML or in another form), and if the graph order is irrelevant, then interoperability issues can arise for use cases where the order is important, for example, in news feeds. However, when HTML is used as the container for RDF, structural elements can be preserved while defining and carrying arbitrary vocabularies (such as FOAF, SIOC, Dublin Core, DOAP, etc.)

Before discussing the details of feed rendering, you need to have a closer look at the environment. ARC2 is a Semantic Web library for PHP. ARC2 is simple to set up and offers useful features. For example, several readers (from microformats over OpenID to RSS) are built in, which allows you to parse a wide range of structured data formats and have them available in RDF. Further, ARC2 supports all common RDF serializations, such as RDF/XML, Turtle, Ntriple, and several plug-ins that extend the functionality of the base system. With ARC2 you can implement a compliant SPARQL end point with only three lines of code. The SPARQL-based scripting mechanism was added recently. These capabilities make ARC2 a multiple-use tool that you can use to create an RSS 1.0-to-RDFa converter service; as shown in the following:


include_once("../../Apache2.2/htdocs/arc2/ARC2.php");

/* ARC RDF store config */
$config = array(
  'db_host' => 'localhost',
	'db_name' => 'arcdb',
	'db_user' => 'arc',
	'db_pwd' => '',
	'store_name' => 'rss2rdfa'
);

$store = ARC2::getStore($config);

/* global store init (one shot)*/	
if (!$store->isSetUp()) {
  $store->setUp();
}
First, declare the prefix mappings that are usable in the entire store:

$NAMESPACES = array(
	'xsd' => 'http://www.w3.org/2001/XMLSchema#',
  	'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  	'rdfa' => 'http://www.w3.org/1999/xhtml/vocab#',
  	'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
	'owl' => 'http://www.w3.org/2002/07/owl#',
  	'foaf' => 'http://xmlns.com/foaf/0.1/',
  	'dc' => 'http://purl.org/dc/elements/1.1/', 
  	'dcterms' => 'http://purl.org/dc/terms/',
  	'skos' => 'http://www.w3.org/2004/02/skos/core#',
  	'sioc' => 'http://rdfs.org/sioc/ns#',
  	'sioct' => 'http://rdfs.org/sioc/types#',
  	'xfn' => 'http://gmpg.org/xfn/11#',
  	'twitter' => 'http://twitter.com/',
  	'rss' => 'http://purl.org/rss/1.0/'   	
);
  Next Page: Generating the RDFa-based Feed
Page 1: IntroductionPage 2: Generating the RDFa-based Feed
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs