We needed to populate some training course and class rosters into Sakai to let people play with site creation, roster attachment, and publishing tests to students. While we could have used webservices, we decided to leverage the built-in CmSyncJob and generate an XML file to dump out the data, and then sync it into the CMS (we wanted something easy to check into SVN for future usage).
The fun part was it let me use Ruby’s Builder (originally part of rails, but then extracted) to produce the XML, which was fun. Builder has a nice Ruby syntax that uses
1 | method_missing |
to allow a nice language to XML mapping:
puts "* Writing Academic Sessions..." xml.tag!("academic-sessions") { 2008.upto(2012) { |i| xml.tag!("academic-session") { xml.eid(i) xml.title("#{i-1}-#{i} School Year") xml.description("#{i-1}-#{i} School Year") xml.tag!("start-date","6/1/#{i-1}") xml.tag!("end-date", "8/31/#{i}")
And just run though a bunch of loops, and pretty clean method calls to spit out XML.
Thanks to http://blog.katipo.co.nz/?p=29 for the tips on Builder, especially the bit about using
1 | tag! |
to put in names which would translate to Ruby keywords (e.g.
1 | start-date |
where the – makes it
1 | start - date |
otherwise)