# Parsing variable length XML?

**URL:** <https://www.ruby-forum.com/t/parsing-variable-length-xml/107372>\
**Category:** Rails\
**Created:** [June 20, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/parsing-variable-length-xml/107372 "2007-06-20T23:35:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 20, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/parsing-variable-length-xml/107372/1 "2007-06-20T23:35:49Z")

</div>

I’m new to Ruby and need to write some code to parse a variable length  
XML structure like the one below. In the below case, the time  
can occur a variable number of times. I want to store each one of  
these port numbers into a separate database record.

Also, is there anyway for Rails to automatically insert these into a  
relational set of models. For instance, the Address record would  
contain the ‘host’ and then a many to many relationship to a bunch of  
port numbers. Are there any features or libraries to make this mapping  
easier when parsing?

Thanks  
Chirag

 example.org 1234 5678 ... 6789

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 21, 2007, 12:36am UTC](https://www.ruby-forum.com/t/parsing-variable-length-xml/107372/2 "2007-06-21T00:36:46Z")

</div>

chirag wrote:

> I’m new to Ruby and need to write some code to parse a variable length  
> XML structure like the one below. In the below case, the time  
> can occur a variable number of times. I want to store each one of  
> these port numbers into a separate database record.
> 
> Also, is there anyway for Rails to automatically insert these into a  
> relational set of models. For instance, the Address record would  
> contain the ‘host’ and then a many to many relationship to a bunch of  
> port numbers. Are there any features or libraries to make this mapping  
> easier when parsing?
> 
> Thanks  
> Chirag
> 
> example.org 1234 5678 ... 6789

Do a Google search for REXML. It’s a standard Ruby library. It will do  
all the XML parsing you need.

–Al Evans
