title: Customize Rails Hash.from_xml with custom conversion
body: <p>I want to convert my XML document to Hash in Ruby/Rails. Actually, the default conversion by Hash.from_xml in Rails works for me except in one case.</p>
  
  <p>I have a list of items contained in <code>&lt;item-list&gt;</code> element, these items can be of different types though. For instance, <code>standard-item</code> and <code>special-item</code>, each of which has different set of child elements.</p>
  
  <pre><code>&lt;item-list&gt;
    &lt;standard-item&gt;
      &lt;foo&gt;...&lt;/foo&gt;
      &lt;bar&gt;...&lt;/bar&gt;
    &lt;/standard-item&gt;
    &lt;standard-item&gt;
      &lt;foo&gt;...&lt;/foo&gt;
      &lt;bar&gt;...&lt;/bar&gt;
    &lt;/special-item&gt;
    &lt;special-item&gt;
      &lt;baz&gt;...&lt;/baz&gt;
    &lt;/special-item&gt;
  &lt;/item-list&gt;
  </code></pre>
  
  <p>This XML structure can be confusing for Hash.from_xml as it does not know that both standard-item and special-item are both items and should be in the same level. Hence, from the above XML, the hash generated by Hash.from_xml will be:</p>
  
  <pre><code>{ 'item-list' =&gt; { 'standard-item' =&gt; [ { 'foo' =&gt; '...', 'bar' =&gt; '...' },
                                          { 'foo' =&gt; '...', 'bar' =&gt; '...' } ],
                     'special-item'  =&gt; { 'baz' =&gt; '...' } }}
  </code></pre>
  
  <p>But what I want is to have all items as list members, like this:</p>
  
  <pre><code>{ 'item-list' =&gt; [ { 'standard-item' =&gt; { 'foo' =&gt; '...', 'bar' =&gt; '...' } },
                     { 'standard-item' =&gt; { 'foo' =&gt; '...', 'bar' =&gt; '...' } },
                     { 'special-item'  =&gt; { 'baz' =&gt; '...' } } ]
  </code></pre>
  
  <p>Is it possible to extend/customize from_xml so that it performs to way I want to for this case? If it is not possible, what is the best way to achieve this? Given that this is the only element that contains something that deviates from general XML-to-Hash conversion, it does not seem right to me to implement the whole conversion routine where it might have already been implemented for a thousand times. </p>
  
  <p>Another small note, <code>Hash.to_xml</code> also replaces all dashes with underscores. Is there a way to prevent this replacement?</p>