C
CD Baby
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?
<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?