# Xmlsimple: prevent folding multiple elements into array?

**URL:** <https://www.ruby-forum.com/t/xmlsimple-prevent-folding-multiple-elements-into-array/109586>\
**Category:** Ruby\
**Created:** [July 17, 2007, 3:45am UTC](https://www.ruby-forum.com/t/xmlsimple-prevent-folding-multiple-elements-into-array/109586 "2007-07-17T03:45:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slothbear](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@slothbear](https://www.ruby-forum.com/u/slothbear)\
**Post date:** [July 17, 2007, 3:45am UTC](https://www.ruby-forum.com/t/xmlsimple-prevent-folding-multiple-elements-into-array/109586/1 "2007-07-17T03:45:43Z")

</div>

I have some xml that represents a somewhat weirdly formed hash.  
XmlSimple is eating some of my structure.

INPUT:  
  
  
  
state  
  
  
open  
  
  
rate  
  
  
daily  
  
  
duration  
  
  
monthly

XmlSimple.xml\_in(xml, {‘ForceArray’=\>false})

OUTPUT:  
{“map”=\> {  
“time”=\>[“daily”, “monthly”],  
“key”=\>[“state”, “rate”, “duration”],  
“string”=\>“open”  
}  
}

With the arrays folded that way, there’s no way for me to tell that  
the value of “state” is “open”. I don’t really care about the  
“datatypes”. I’m aiming at a single level hash something like this:

DESIRED:  
{“map”=\> {  
“state” =\> "open,  
“rate” =\> “daily”,  
“duration” =\> “monthly”  
}  
}

I can’t really change the odd incoming XML, but I’m happy to process  
any Ruby data structure that hasn’t lost some of my order/structure.  
All of the options around folding appear to affect only attributes,  
but I have only elements.

---

<div class="post-metadata">

**Author:** ![slothbear](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@slothbear](https://www.ruby-forum.com/u/slothbear)\
**Post date:** [July 17, 2007, 4:10am UTC](https://www.ruby-forum.com/t/xmlsimple-prevent-folding-multiple-elements-into-array/109586/2 "2007-07-17T04:10:44Z")

</div>

Man, wish I could help you there. The problem is that the only languages  
that I have been able to work with XML in are ActionScript and Java…  
and Ruby really doesn’t look like either, not to mention I can’t even  
seem to find some decent tutorials that explain it…

Oh well, sorry for taking up space on this thread. But perchance, you  
may want to investigate the REXML library that comes with Ruby. It’s  
just an alternative to XMLSimple.

---

<div class="post-metadata">

**Author:** ![slothbear](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@slothbear](https://www.ruby-forum.com/u/slothbear)\
**Post date:** [July 20, 2007, 2:36am UTC](https://www.ruby-forum.com/t/xmlsimple-prevent-folding-multiple-elements-into-array/109586/3 "2007-07-20T02:36:22Z")

</div>

Thanks for the thoughts! I figured I would have to move to REXML  
eventually, and I guess it’s time. thanks again.
