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.