I have an object that has_many child objects that should be rendered as xml. This is not a problem. My Problem is that I creat a Hash containing this data like the parser needs it. But rails atomaticly encloses the whole file with
<hash>
    <objects type="array">
        <object>
           ...
           ...
           ...
        </object>
    </objects>
</hash>
I need to get rid of the type="array" and the <hash> how can I handle this? I didnt find anything on the documentation.
I was having the same Issue;
This is my XML:
<?xml version="1.0" encoding="UTF-8"?>
<Contacts>
  <Contact type="array">
  </Contact>
</Contacts>
I was using this:
entries.to_xml
to convert hash data into XML, but this wraps entries' data into <hash></hash>
So I modified:
entries.to_xml(root: "Contacts")
but that still wrapped the converted XML in 'Contacts' modifying my XML code to
<Contacts>
 <Contacts>
  <Contact type="array">
   <Contact>
    <Name></Name>
    <Email></Email>
    <Phone></Phone>
   </Contact>
  </Contact>
 </Contacts>
</Contacts>
So it adds an extra ROOT that I don't wan't there.
Now solution to this what worked for me is:
 entries["Contacts"].to_xml(root: "Contacts")
that avoids <hash></hash> or any additional root to be included.
Cheers!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With