# Xml newbie

**URL:** <https://www.ruby-forum.com/t/xml-newbie/107551>\
**Category:** Ruby\
**Created:** [June 23, 2007, 1:28am UTC](https://www.ruby-forum.com/t/xml-newbie/107551 "2007-06-23T01:28:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [June 23, 2007, 1:28am UTC](https://www.ruby-forum.com/t/xml-newbie/107551/1 "2007-06-23T01:28:51Z")

</div>

Okay, so I am scraping the FAA site and keeping track of some airplanes.

A lot of the time I get a tail number and I have it already, so I am  
going to store the important information in a file that is  
{tailnumber}.xml

That way I can add some of my own information (email address of owner,  
airport last sighted).

I’ve never written any xml. But apparently there are gems I could add  
to my Ruby installation which would let me write it.

Suggestions for where to start?

I assume I’ll wind up with a file that has  
DA20  
408.21

and I can say things like  
serial = xml(‘serial’)  
and  
xml(serial) = ‘408.21’  
right?

I can picture writing these things, but I bet someone has already done  
the work.

Thanks,  
–Colin

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [June 23, 2007, 4:28am UTC](https://www.ruby-forum.com/t/xml-newbie/107551/2 "2007-06-23T04:28:06Z")

</div>

On 6/22/07, Colin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to my Ruby installation which would let me write it.
> 
> Suggestions for where to start?

You’ll want to take a look at HPricot[0] and/or XML Builder[1]

[0] [http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)  
[1] [http://rubyforge.org/projects/builder](http://rubyforge.org/projects/builder)

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [June 23, 2007, 6:21am UTC](https://www.ruby-forum.com/t/xml-newbie/107551/3 "2007-06-23T06:21:14Z")

</div>

On Jun 22, 7:27 pm, “Colin S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to my Ruby installation which would let me write it.  
> xml(serial) = ‘408.21’  
> right?
> 
> I can picture writing these things, but I bet someone has already done the work.
> 
> Thanks,  
> –Colin

Why bother with xml at all? For something this small YAML would work  
just as well and requires less work too.

require ‘yaml’  
planes = [ {:tailnumber =\> ‘N1234Z’, :model =\> ‘DA20’, :serial =\>  
‘408.21’},  
{:tailnumber =\> ‘N1234AZ’, :model =\> ‘magic happy  
plane’, :serial =\> ‘42’} ]  
#write planes  
File.open(“planes.yaml”, “w”) { |f| f.puts tree.to\_yaml }

#read planes  
planes = YAML.load(File.open(“planes.yaml”))  
puts planes.first[:serial]  
#408.21

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [June 23, 2007, 6:32am UTC](https://www.ruby-forum.com/t/xml-newbie/107551/4 "2007-06-23T06:32:16Z")

</div>

On 6/23/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I’ve never written any xml. But apparently there are gems I could add  
> > and  
> > xml(serial) = ‘408.21’  
> > right?
> > 
> > I can picture writing these things, but I bet someone has already done the work.
> > 
> > Thanks,  
> > –Colin
> 
> Why bother with xml at all? For something this small YAML would work  
> just as well and requires less work too.

Oh, for some reason I thought the OP was scraping XML files and wanted  
to keep the structure intact but just change parts. If all that is  
needed is data persistence, YAML is a better choice for sure.

---

<div class="post-metadata">

**Author:** ![banry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/898d66/32.png) [@banry](https://www.ruby-forum.com/u/banry)\
**Post date:** [June 23, 2007, 6:22am UTC](https://www.ruby-forum.com/t/xml-newbie/107551/5 "2007-06-23T06:22:14Z")

</div>

On Jun 23, 12:16 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > That way I can add some of my own information (email address of owner,
> 
> #read planes  
> planes = YAML.load(File.open(“planes.yaml”))  
> puts planes.first[:serial]  
> #408.21

Errr tree.to\_yaml should of course be planes.to\_yaml. It’s late 🙂
