 | Level: Intermediate Daniel Wintschel (daniel@humandoing.net), Software developer, Helium Syndicate
17 Apr 2007 You've very likely heard of Ruby on Rails. Maybe you've actually used it; perhaps it is your new programming mistress. Whatever the case, it looks like Rails is here to stay, and to everyone's benefit. Ruby plays very nicely with XML -- read further for the details.
In this tutorial
In the past couple of years, Ajax has practically become a requirement for new Web sites,
but that doesn't make it any easier to create. To create Ajax-enabled sites manually means that you create
JavaScript to make asynchronous HTTP requests using objects that do not comply with browser standards, which can make for a very long programming day. The Google Web Toolkit (GWT) abstracts the JavaScript tasks necessary for an Ajax-enabled application into a few Java classes, to make creating these interfaces much more intuitive for Java programmers. But most of these Ajax applications use XML to transfer
information to and from the server, so your application must be able to both parse and create
XML data. In this tutorial, you will build a Rails application, discuss some basics about the way that Rails works, how it's structured and how to use it, and then you'll move on to working with XML. There are a number of ways to both generate and parse XML in Ruby, and you'll look at a few of them, including REXML (Ruby Electric XML), Builder and Hpricot (Technically Hpricot is an HTML parser -- but it's fast, and works on XML, too).
Objectives - Build the skeletal Ruby on Rails app (preparation for XML processing)
- Create a new XML document
- Download the XML document
- Upload a file in Rails (in this case, XML)
- Parse and manipulate XML
Prerequisites
This tutorial is for a general programming crowd interested in learning the basics of setting up a skeleton Rails application and using Ruby and Rails to process XML. Beginner and intermediate programmers or people who have a little bit of exposure to Rails will likely benefit the most. It will spend a brief amount of time discussing Rails in general, and Ruby syntax as necessary, but these topics are covered in much better detail elsewhere. Please see Resources in the tutorial for additional information.
System requirements
You will need JavaScript enabled in your browser. The following tools are needed to follow along with this tutorial:
- Ruby -- If you run Windows, your best bet is to download the One-Click Ruby Installer. If you use some variation of Linux or Mac OS X, you might already have Ruby installed. If not, you can download it from http://www.ruby-lang.org. The installation instructions are straightforward. Version 1.8.4 or 1.8.5 is recommended.
-
RubyGems -- Get the gems you need, and install Rails, Builder and Hpricot if you haven't already.
-
Rails -- You can install Rails through RubyGems. While not really part of this discussion, you figure all that out at http://www.rubyonrails.com/down. You'll use version 1.2.2 for this tutorial.
- Builder -- Install through RubyGems.
- Hpricot -- Install through RubyGems.
Duration
1 hour
Formats html, pdf
|  | |  |