Skip to content

Instantly share code, notes, and snippets.

@brookemckim
Created July 13, 2011 17:54
Show Gist options
  • Save brookemckim/1080863 to your computer and use it in GitHub Desktop.
Save brookemckim/1080863 to your computer and use it in GitHub Desktop.
Build XML from template w/ Nokogiri
template = File.read('/path/to/template')
builder = Nokogiri::XML::Builder.new do |xml|
eval File.read(template)
end
builder.to_xml
xml.root {
xml.categories {
@categories.each do |cat|
xml.category {
xml.title cat.title
xml.videos {
cat.videos.each do |vid|
xml.video {
xml.title vid.title
xml.description vid.description
xml.live vid.live
xml.format vid.format
xml.medias {
xml.media {
xml.url vid.url
xml.bitrate vid.bitrate
xml.quality vid.quality
}
}
xml.sd_image ''
xml.hd_image ''
}
end
}
}
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment