# Creating '.plist' (XML) file in ruby 2.1

**URL:** <https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495>\
**Category:** Ruby\
**Created:** [April 16, 2014, 11:54pm UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495 "2014-04-16T23:54:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [April 16, 2014, 11:54pm UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495/1 "2014-04-16T23:54:14Z")

</div>

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](https://gist.github.com/atmosx/10936292)

Panagiotis (atmosx) Atmatzidis

email: removed\_email\_address@domain.invalid  
URL: [http://www.convalesco.org](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

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [April 17, 2014, 4:56am UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495/2 "2014-04-17T04:56:58Z")

</div>

On 17/04/2014, at 9:53 am, Panagiotis A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

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

> **[GitHub - caseyhoward/nokogiri-plist: A PList parser and generator built using Nokogiri](https://github.com/caseyhoward/nokogiri-plist)**
>
> A PList parser and generator built using Nokogiri

Henry

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [April 17, 2014, 7:36am UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495/3 "2014-04-17T07:36:11Z")

</div>

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

Quoting Panagiotis A. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> 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](http://www.germane-software.com)) is currently not reachable, but some  
docs are here:

> **[Index of Classes & Methods in rexml: Ruby Standard Library Documentation...](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

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [April 18, 2014, 3:02am UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495/4 "2014-04-18T03:02:35Z")

</div>

On Thu, Apr 17, 2014 at 12:35 AM, Carlo E. Prelz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> Subject: Creating '.plist' (XML) file in ruby 2.1
> Date: Wed 16 Apr 14 11:53:28PM +0200
> 
> ```
> 
> Quoting Panagiotis A. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):
> 
> > 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. · GitHub](https://github.com/jimweirich/builder)

---

<div class="post-metadata">

**Author:** ![atma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/858c86/32.png) [@atma](https://www.ruby-forum.com/u/atma)\
**Post date:** [April 18, 2014, 4:14pm UTC](https://www.ruby-forum.com/t/creating-plist-xml-file-in-ruby-2-1/240495/5 "2014-04-18T16:14:06Z")

</div>

Hello,

thank you all for the replies

On 18 Απρ 2014, at 03:01 , tamouse pontiki [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Thu, Apr 17, 2014 at 12:35 AM, Carlo E. Prelz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > Subject: Creating '.plist' (XML) file in ruby 2.1
> > Date: Wed 16 Apr 14 11:53:28PM +0200
> > 
> > ```
> > 
> > Quoting Panagiotis A. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):
> > 
> > > 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. · GitHub](https://github.com/jimweirich/builder)

this solution seems to be the easier thanks!

Panagiotis (atmosx) Atmatzidis

email: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
URL: [http://www.convalesco.org](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
