Hello,
I’d like to create the following ‘.plist’ (XML) file[1] from within a
ruby program:
<?xml version="1.0" encoding="UTF-8"?>
Label
org.atma.local
ProgramArguments
/Users/atma/Code/scripts/local.sh
StartInterval
3600
RunAtLoad
I would like to have variables for ‘integer’ (e.g. <%= var
%> or something). What is the best way to create a predefined
file? I’ve code around using a strange notation ‘<<’ when it comes to
dumping lines of text or XML into ruby scripts but I can’t find any
specific examples right now.
best regards,
[1] https://gist.github.com/atmosx/10936292
Panagiotis (atmosx) Atmatzidis
email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
“As you set out for Ithaca, hope the voyage is a long one, full of
adventure, full of discovery […]” - C. P. Cavafy
atma
April 17, 2014, 4:56am
2
On 17/04/2014, at 9:53 am, Panagiotis A. [email protected]
wrote:
Hello,
I’d like to create the following ‘.plist’ (XML) file[1] from within a ruby
program:
Henry
atma
April 17, 2014, 7:36am
3
Subject: Creating ‘.plist’ (XML) file in ruby 2.1
Date: Wed 16 Apr 14 11:53:28PM +0200
Quoting Panagiotis A. ([email protected] ):
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:
Label
There is some useful info in
ri REXML::Document
and
ri REXML::Element
Carlo
atma
April 18, 2014, 3:02am
4
On Thu, Apr 17, 2014 at 12:35 AM, Carlo E. Prelz [email protected]
wrote:
Subject: Creating '.plist' (XML) file in ruby 2.1
Date: Wed 16 Apr 14 11:53:28PM +0200
Quoting Panagiotis A. ([email protected] ):
I’d like to create the following ‘.plist’ (XML) file[1] from within a ruby
program:
I use builder: GitHub - jimweirich/builder: Provide a simple way to create XML markup and data structures.
atma
April 18, 2014, 4:14pm
5
Hello,
thank you all for the replies
On 18 Απρ 2014, at 03:01 , tamouse pontiki [email protected]
wrote:
On Thu, Apr 17, 2014 at 12:35 AM, Carlo E. Prelz [email protected] wrote:
Subject: Creating '.plist' (XML) file in ruby 2.1
Date: Wed 16 Apr 14 11:53:28PM +0200
Quoting Panagiotis A. ([email protected] ):
I’d like to create the following ‘.plist’ (XML) file[1] from within a ruby
program:
I use builder: GitHub - jimweirich/builder: Provide a simple way to create XML markup and data structures.
this solution seems to be the easier thanks!
Panagiotis (atmosx) Atmatzidis
email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
“As you set out for Ithaca, hope the voyage is a long one, full of
adventure, full of discovery […]” - C. P. Cavafy