Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry to see no one answered your question! I'll give it a try, although I'm not totally sure I follow what it is.</p> <p>If I understand you correctly, you should be able to get what you want by doing the following:</p> <pre><code>arrayHash.to_xml(:root =&gt; "Cenarios", :skip_types =&gt; true, :skip_instruct =&gt; true) </code></pre> <p>Note that I changed the root to <code>Cenarios</code> plural. This will give you XML like this:</p> <pre><code>&lt;Cenorios&gt; &lt;Cenorio&gt; &lt;TamanhoRegistro&gt; &lt;nomeCampo&gt;Tamanho Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/TamanhoRegistro&gt; &lt;VersaoRegistro&gt; &lt;nomeCampo&gt;Versao Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/VersaoRegistro&gt; &lt;/Cenorio&gt; &lt;/Cenorios&gt; </code></pre> <p>Or were you saying that you want <code>TamanhoRegistro</code> and <code>VersaoRegistro</code> and such to be changed to <code>Cenario</code>? If so, assuming your arrayHash is something like this:</p> <pre><code>arrayHash = [hashExemplo, otherHash] </code></pre> <p>you could do something like this:</p> <pre><code>arrayHash.map(&amp;:values).flatten.to_xml(:root =&gt; "Cenorios", :skip_types =&gt; true) </code></pre> <p>which would give you XML like the following:</p> <pre><code>&lt;Cenorios&gt; &lt;Cenorio&gt; &lt;nomeCampo&gt;Tamanho Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/Cenorio&gt; &lt;Cenorio&gt; &lt;nomeCampo&gt;Versao Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/Cenorio&gt; &lt;Cenorio&gt; &lt;nomeCampo&gt;Tamanho Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/Cenorio&gt; &lt;Cenorio&gt; &lt;nomeCampo&gt;Versao Registro&lt;/nomeCampo&gt; &lt;X&gt;10&lt;/X&gt; &lt;Y&gt;20&lt;/Y&gt; &lt;valor&gt;10&lt;/valor&gt; &lt;/Cenorio&gt; &lt;/Cenorios&gt; </code></pre> <p>Essentially, #map will iterate over the array, getting an array from each hash of the values in the hash, so the array will now be an array of arrays, so #flatten flattens that into a single array.</p> <p>Does that answer your question, or have I missed something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload