Write to XML in ruby

Tags: xml ruby file

I am completely new to Ruby. All I want is to produce a simple XML file.

<?xml version="1.0" encoding="ASCII"?>

That's it.


Simply with Nokogiri::XML::Builder

require 'nokogiri'

builder = Nokogiri::XML::Builder.new(:encoding =

Here are a couple more options for constructing XML in Ruby

REXML - built-in but is very slow especially when dealing with large documents

Nokogiri - newer and faster, installs as a rubygem

LibXML-Ruby - built on the C libxml library, also installs as a rubygem

If you can't install rubygems then REXML is your best options. If you are going to be creating large complex XML docs then Nokogiri or LibXML-Ruby is what you would want to use.

You can use builder to generate xml.

By : sepp2k

This video can help you solving your question :)
By: admin