ruby-rdf / rdf-rdfxml

Ruby RDF/XML reader/writer for RDF.rb.
http://rubygems.org/gems/rdf-rdfxml
The Unlicense
17 stars 7 forks source link

Problems with adding node with no content #32

Closed a-andreyev closed 9 years ago

a-andreyev commented 9 years ago

Am I right that something wrong with RDF::Writer while working with rdf:resource type of object?

require 'rdf/rdfxml'

output = RDF::Writer.for(:rdfxml).buffer do |writer|
  subject = RDF::Node.new
  writer << [subject, RDF.type, RDF::FOAF.Person]
  writer << [subject, RDF::FOAF.name, "J. Random Hacker"]
  writer << [subject, RDF::FOAF.mbox, RDF::URI("mailto:jhacker@example.org")]
  writer << [subject, RDF::FOAF.nick, "jhacker"]
end
puts output.dump()

Output looks like:

<?xml version='1.0' encoding='utf-8' ?>
<rdf:RDF xmlns:ns0='http://xmlns.com/foaf/0.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<ns0:Person>
<ns0:mbox rdf:resource='mailto:jhacker@example.org'>
<ns0:name>J. Random Hacker</ns0:name>
<ns0:nick>jhacker</ns0:nick>
</ns0:Person>
</rdf:RDF>

Am I right that unclosed tags <ns0:Person> and <ns0:mbox rdf:resource='mailto:jhacker@example.org'> are wrong?

gkellogg commented 9 years ago

ns0:Person is closed (next to last line). ns0:mbox should be self-closing, and this might be an issue with the Haml generator, I'll look into it.

a-andreyev commented 9 years ago

Is Issue closed? Should ns0:mbox be self-closing?

gkellogg commented 9 years ago

It is self closing, when I run the example using Ruby 2.1.4, anyway. The only way for it to not self-close if you had an odd version of Haml, AFAIK. If you have some better steps to reproduce, then I'm happy to re-open and look further into it; better give details about your platform, ruby version, and gem versions. Consider doing a bundle install within the gem directory and run using bundle exec irb -Ilib -r rdf/rdfsml.

My output looks like the following:

<?xml version='1.0' encoding='utf-8' ?>
<rdf:RDF xmlns:ns0='http://xmlns.com/foaf/0.1/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
  <ns0:Person>
    <ns0:mbox rdf:resource='mailto:jhacker@example.org' />
    <ns0:name>J. Random Hacker</ns0:name>
    <ns0:nick>jhacker</ns0:nick>
  </ns0:Person>
</rdf:RDF>
a-andreyev commented 9 years ago

Thank you!! Found that I had haml-4.1.0.beta.1 version (not sure how I've got exactly this version), which contains this problem. Switching to haml-4.0.5 fixed the problem.