XML/RSS generation

Hi guys,

Can anyone point em in the direction of a good tutorial/manual for
creating xml files from within ruby?

What I want to do is take a bunch of information and output it into a
format such as:
<post title="My Post Title>
This is the text
Vector Info

and then save it to the server in a filename such as:
username-timestamp.xml.

The xml file would be formated as rss as well so that rss clients can
read it.

Thanks guys
~Chris

On Jun 15, 2006, at 17:09, Chris Watt wrote:

and then save it to the server in a filename such as: username-
timestamp.xml.

This might be a start: http://builder.rubyforge.org/

matthew smillie.

Yea I did find that but it doesn’t answer a few of my questions (and
as yet google hasn’t yielded anything).

I don’t know how to make ruby parse it all into a file
(username-timestamp.xml) and how to add the extra statements to the
vector tag (i.e., bg=“bg.png”, etc…)

They seem to be my main problems at the moment.

Also, on a related note, how do I put something into a varialbe to
reuse it later? as php would be :
$var=“contents of var”;
echo “$var”;

etc.

Cheers
~Chris

On Jun 15, 2006, at 17:29, Chris Watt wrote:

Yea I did find that but it doesn’t answer a few of my questions (and
as yet google hasn’t yielded anything).

I don’t know how to make ruby parse it all into a file
(username-timestamp.xml) and how to add the extra statements to the
vector tag (i.e., bg=“bg.png”, etc…)

They seem to be my main problems at the moment.

There’s actually an example of creating attributes (“extra
statements”) right on the first page of the xml docs. Anyway, this
should do something close to what you want (with some explanation):

builder = Builder::XmlMarkup.new(:indent => 2)

opens the post tag

xml = builder.post(:title => “This is the title”) { |post|

create the text tag and its contents inside the post tag.

post.text(“This is the text”)

ditto, the vector tag.

post.vector(“Vector Info”, :bg => “bg.png”, :opacity => “80%”)
}

Writing files is well-documented under the File class in the standard
docs, which you can find online at ruby-doc.org, but this is a start:

File.new(“filename”).open { |file|
file.write(xml)
}

Also, on a related note, how do I put something into a varialbe to
reuse it later? as php would be :
$var=“contents of var”;
echo “$var”;

Maybe you should read up on the basics:
http://whytheluckystiff.net/ruby/pickaxe/
http://poignantguide.net/ruby/

It covers the basics like how variables work pretty well, including
interpolation in strings using the #{} construct, and has plenty on I/
O too. It’s quite useful.

matthew smillie.