W3C home > Mailing lists > Public > public-rdf-ruby@w3.org > June 2010

Re: Writing Namespaces in RDF.rb

From: Gregg Kellogg <gregg@kellogg-assoc.com>
Date: Tue, 8 Jun 2010 08:37:46 -0400
To: Mark Windholtz <windholtz@gmail.com>
CC: "public-rdf-ruby@w3.org" <public-rdf-ruby@w3.org>
Message-ID: <8AAA2648-B8D5-429F-8CA5-C30741EDE96F@kellogg-assoc.com>
Hi Mark, just to note that the rdf-rdfxml RDF/XML Writer is still in development, so your results may vary. Which gem are you using to do rdfxml formatting?

In this case, you're using standard namespaces, so the writer should find them to use them in the serialization. Note that for non-standard namespaces (those not defined in RDF.rb), you can define them buy subclassing RDF::Vocabulay as follows:

class XML < Vocabulary("http://www.w3.org/XML/1998/namespace"); end

This should cause the namespaces to be used in serialization.

Alternatively, the rdf_context gem also includes an RDF/XML serializer, but the syntax is somewhat different than that for RDF.rb.

require 'rdf_context'
include RdfContext

g = Graph.new
g << Triple.new(course_url(@course), DC_NS.event, @course.full_title)
output = g.to_rdfxml


<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:dc="http://purl.org/dc/terms/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about="http://foo/bar">


On Jun 6, 2010, at 4:52 PM, Mark Windholtz wrote:

I'm an RDF.rb newbie trying to write out RDF for a training event.
But I cannot figure out how to write out the namespace specs.
The Rails action looks like this:

def show
 @course = Course.find(params[:id])
 respond_to do |format|
     format.rdf  do
            output = RDF::Writer.for(:rdfxml).buffer do |writer|
                 s = RDF::URI(course_url(@course))
                 p = RDF::DC.event
                 o = RDF::Literal(@course.full_title)
                 writer << RDF::Statement(s, p, o)
            render :xml => output

And produces this:
   <rdf:Description rdf:about="http://mydomain/training/178">
   <ns0:event>  Training: Dallas, Aug 23-24, 2010 </ns0:event>

Why is the namespace "ns0" ?
I want something like:

   xmlns:dc="http://purl.org/dc/elements/1.1" >           <==== NOTE HERE
   <rdf:Description rdf:about="http://mydomain/training/178">
   <dc:event>  Training: Dallas, Aug 23-24, 2010 </ns0:event>

How can I get RDF.rb to do this?

- Mark Windholtz
(513) 226-8259
Received on Tuesday, 8 June 2010 12:39:28 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:02:14 UTC