SRXML - Simple Ruby XML Created by Christopher Bertels ([email protected] / github.com/bakkdoor/)

SRXML is a very (super, if you will!) lightweight xml generator for Ruby. No big magic here, it simply uses method_missing to create the tags. There is some plan to make it more useful. For Example being able to parse existing files etc. but there are probably better libraries to do that. If you simply want to create an xml file without the need for extra fancy formatting, SRXML could just be the deal for you!

Oh, by the way. It also supports html-output now.

LICENSE:

SRXML is licensed under the terms of the GNU GPL v2. Play with it as much as you like, fork it and put the changes here back on github or so :)

Short Example (from examble.rb):

require "rubygems"
require "srxml"

xml = SRXML::XML.new

xml.projects{
  xml.project(:name => "project #1", :description => "some text", :id => 1){
    xml.something_else "yo!"
  }
}

puts xml.to_s

Will output the following:

<?xml version="1.0" encoding="UTF-8"?><projects><project name="project #1" description="some text" id="1"><something_else>yo!</something_else></project></projects>

You can also use some simple formatting:

puts xml.to_s(:formatted)

Which will then give you something like this:

<?xml version="1.0" encoding="UTF-8"?><projects>
<project name="project #1" description="some text" id="1">
<something_else>yo!</something_else>
</project>
</projects>

Simple HTML generation:

SRXML now also supports html-output:

require "rubygems"
require "srxml"

html = SRXML::XML.new :xml => false, :html => true  # this will automatically set SRXML into 'html-mode',
                                                    # knowing for example, that certain tags are single (no end tag) 
html.html{
  html.head{
    html.title "my title"
  }
  html.body{
    html.div(:style => "padding:10em; font-size: 140%"){
      "hello, world!"
    }
  }
}

puts html.to_s

Will output the expected html-output.

For more examples take a look in the example-files.