Say I'm trying to make this XML:
<music>
<artist>Pink Floyd</artist>
<album>Dark Side of the Moon</album>
</music>
Right now I'm doing this:
doc = Document.new
music = doc.add_element 'music'
artist = music.add_element 'artist'
artist.text = 'Pink Floyd'
album = music.add_element 'album'
album.text = 'Dark Side of the Moon'
QUESTION:
Why create variables for artist and album?
Shouldn't there be a way to add the text directly, without creating an
in-between (and never used again) variable?
Like this:
music.add_element('album').text = 'Dark Side of the Moon'
or this:
music.add_element('album').text << Text.new('Dark Side of the Moon')
doc = Document.new
music = doc.add_element("music")
music << Element.new("artist").add_text("Pink Floyd")
music << Element.new("album").add_text("Dark side of the moon")
//Anders
···
On Sun, Jul 18, 2004 at 12:09:25PM +0900, CD Baby wrote:
Say I'm trying to make this XML:
<music>
<artist>Pink Floyd</artist>
<album>Dark Side of the Moon</album>
</music>
Right now I'm doing this:
doc = Document.new
music = doc.add_element 'music'
artist = music.add_element 'artist'
artist.text = 'Pink Floyd'
album = music.add_element 'album'
album.text = 'Dark Side of the Moon'
QUESTION:
Why create variables for artist and album?
Shouldn't there be a way to add the text directly, without creating an
in-between (and never used again) variable?
Like this:
music.add_element('album').text = 'Dark Side of the Moon'
or this:
music.add_element('album').text << Text.new('Dark Side of the Moon')
Has anyone found a shortcut like this?
--
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. Anders Engström aengstrom@gnejs.net
. http://www.gnejs.net PGP-Key: ED010E7F
. [Your mind is like an umbrella. It doesn't work unless you open it.]
Thanks everyone for your help.
You're right, this works great:
doc2 = REXML::Document.new
music = doc2.add_element 'music'
music.add_element('artist').text = 'Pink Floyd'
music.add_element('album').text = 'Dark Side of the Moon'
Not sure why it wasn't working last night, except maybe I needed some
sleep.
Thanks everyone for your help.
You're right, this works great:
doc2 = REXML::Document.new
music = doc2.add_element 'music'
music.add_element('artist').text = 'Pink Floyd'
music.add_element('album').text = 'Dark Side of the Moon'
Not sure why it wasn't working last night, except maybe I needed some
sleep.