[WIP] Xommelier: The XML Sommelier. XML←→Ruby mapper with batteries (Atom, RSS, etc) included.
Ruby XSLT Shell
Failed to load latest commit information.
bin Do not require Pry twice Jul 5, 2016
config Copyrights added Aug 29, 2013
.gitignore Remove old IDE gems Jul 5, 2016
.rspec Configured Yard and RSpec rake tasks Aug 16, 2011
.rubocop.yml Fix code style with help of Rubocop Jul 5, 2016
.travis.yml Update Travis CI configuration Jan 10, 2016
xommelier.gemspec CodeClimate Test Coverage Jul 5, 2016


Xommelier is an XML Sommelier


Xommelier is an XML Object Mapper. You could describe some namespace (e.g. Atom) in ruby DSL and use it for parsing XML to Ruby objects or for building XML from Ruby objects.

Look into {Xommelier::Atom}, {Xommelier::Atom::Threading}, and {Xommelier::Atom::History} module for implementation of http://www.w3.org/2005/Atom namespace, Atom Threading, and Feed Paging and Archiving extensions

Project links

Examples with Atom

require 'xommelier/atom/full'

Reading a feed

feed = Xommelier::Atom::Feed.parse(open('spec/fixtures/feed.atom.xml'))
puts feed.id, feed.title, feed.updated

feed.entries do |entry|
  puts feed.id, feed.title, feed.published, feed.updated
  puts feed.content || feed.summary

Building a feed

feed = Xommelier::Atom::Feed.new
feed.id = 'http://example.com/blog'
feed.title = 'Example.com blog'
feed.complete = Xommelier::Atom::History::Complete.new

entry = feed.entry = Xommelier::Atom::Entry.new(
  id: 'http://example.com/blog/2012/03/05',
  title: "Happy Xommelier's day!",
  updated: 5.days.ago
).tap do |entry|
  entry.link = Xommelier::Atom::Link.new(
    href: entry.id,
    rel:  'alternate',
    type: 'text/html'
  entry.links << Xommelier::Atom::Link.new(
    href:  "#{entry.id}/comments.atom",
    rel:   'replies',
    type:  'application/atom+xml',
    count: 5

# Add Comments
3.times do |i|
  feed.entries << Xommelier::Atom::Entry.new(
    id: "http://example.com/blog/2012/03/05#comment_#{i}",
    title: ('Hooray! ' * (i + 1)).strip,
    updated: (5 - i).days.ago
  ).tap do |comment|
    comment.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new(
      ref: entry.id,
      href: entry.link.href

puts feed.to_xml

will output:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:fh="http://purl.org/syndication/history/1.0">
  <title>Example.com blog</title>
    <title>Happy Xommelier's day!</title>
    <link href="http://example.com/blog/2012/03/05" rel="alternate" type="text/html"/>
    <link href="http://example.com/blog/2012/03/05/comments.atom" rel="replies" type="application/atom+xml" thr:count="5"/>
    <thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/>
    <title>Hooray! Hooray!</title>
    <thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/>
    <title>Hooray! Hooray! Hooray!</title>
    <thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/>

Building from hash

feed = Xommelier::Atom::Feed.new(
    title: 'Xommelier nest elements',
    subtitle: 'Xommelier is able to build complex objects from very nested hash',
    author: {name: 'Alexander', email: 'al@semyonov.us'},
    updated: Time.utc(2012, 04, 04, 04, 04),
    contributors: [
      {name: 'Ivan', email: 'ivan@example.com'},
      {name: 'Pyotr', email: 'pyotr@example.com'},
      {name: 'Sidor', email: 'sidor@example.com'},
    entries: [
      {title: 'First article', updated: Time.utc(2012, 01, 01, 01, 01)},
      {title: 'Second article', updated: Time.utc(2012, 02, 02, 02, 02)},
      {title: 'Third article', updated: Time.utc(2012, 03, 03, 03, 03)},

feed.author # Xommelier::Atom::Person
feed.contributors[1] # Xommelier::Atom::Person
feed.entries[2] # Xommelier::Atom::Entry

puts feed.to_xml

will output

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Xommelier nest elements</title>
  <subtitle>Xommelier is able to build complex objects from very nested hash</subtitle>
    <title>First article</title>
    <title>Second article</title>
    <title>Third article</title>

Built in XML namespaces:

  1. {Xommelier::Atom} - http://www.w3.org/2005/Atom
  2. {Xommelier::Atom::Threading} - http://purl.org/syndication/thread/1.0
  3. {Xommelier::Atom::History} - http://purl.org/syndication/history/1.0
  4. {Xommelier::OpenSearch} - http://a9.com/-/spec/opensearch/1.1/


  • Validating built XML against RelaxNG
  • Converting XML Schema, RelaxNG, RelaxNG Compact and DTD into Xommelier Ruby DSL
  • ActiveRecord-like automatic loading of XML Schema, RelaxNG, RelaxNG Compact and DTD without needing to write it down into ruby code


  • Artyom Semyonov
  • Sergey Ukustov

© Alexander Semyonov, 2011-2012. See MIT-LICENSE for details

Bitdeli Badge