Re: Writing Namespaces in RDF.rb

This is actually a problem with rdf-raptor, not rdf-rdfxml.  I imagine
Mark is using require 'linkeddata'.

However, I don't replicate a simpler example (now copy-pasteable):

require 'linkeddata'
s = RDF::URI('http://example.org/ex')
p = RDF::DC.event
o = RDF::Literal("a literal")
repo = RDF::Repository.new
repo << RDF::Statement(s, p, o)
RDF::Writer.for(:ntriples)
RDF::Writer.for(:rdfxml)

For this :rdfxml dump, I get:

<?xml version="1.0" encoding="utf-8"?>\n<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about="http://example.org/ex">
    <ns0:event xmlns:ns0="http://purl.org/dc/terms/">a literal</ns0:event>
    </rdf:Description>
</rdf:RDF>\n

Note that the namespace is defined in mine.  Can you verify you're
using the latest rdf-raptor and rdf.rb, Mark?

Ben

On Tue, Jun 8, 2010 at 2:37 PM, Gregg Kellogg <gregg@kellogg-assoc.com> wrote:
> 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
> @agiledna
>
>
>
>
>
>
>

Received on Tuesday, 8 June 2010 12:56:49 UTC