Re: Writing Namespaces in RDF.rb

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

yields

<?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">
    <dc:event>title</dc:event>
  </rdf:Description>
</rdf:RDF>

Gregg

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)
            end
            render :xml => output
        end
  end
end

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

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

<rdf:RDF
   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>
 </rdf:Description>
</rdf:RDF>

How can I get RDF.rb to do this?

Regards,
- Mark Windholtz
(513) 226-8259
www.agiledna.com<http://www.agiledna.com>
@agiledna

Received on Tuesday, 8 June 2010 12:39:28 UTC