Subject: Creating '.plist' (XML) file in ruby 2.1
	Date: Wed 16 Apr 14 11:53:28PM +0200

Quoting Panagiotis Atmatzidis (atma / convalesco.org):

> I'd like to create the following '.plist' (XML) file[1] from within a ruby program:

The XML library that's included in MRI (REXML) allows you to write XML
programmatically. Sadly, the documentation site indicated in the RI
page (www.germane-software.com) is currently not reachable, but some
docs are here:

http://ruby-doc.org/stdlib-2.1.1/libdoc/rexml/rdoc/index.html

If you are just interested in XML code that's correctly parsed
(i.e. you do not care about the resulting indentation), you can start
like this:

--8<----8<----8<----8<----8<--
require 'rexml/rexml'
require 'rexml/document'

d=REXML::Document::new

n=REXML::Element::new('plist')
n.add_attribute('version','1.0')
d.push(n)

n2=REXML::Element::new('dict')
n.push(n2)

n3=REXML::Element::new('key')
n3.add_text('Label')
n2.push(n3)

#
# go on inserting elements
#

d.write
--8<----8<----8<----8<----8<--

The above example gives:

<plist version='1.0'><dict><key>Label</key></dict></plist>

There is some useful info in

ri REXML::Document

and 

ri REXML::Element

Carlo

-- 
  *         Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido / fluido.as             che bisogno ci sarebbe
  *               di parlare tanto di amore e di rettitudine? (Chuang-Tzu)