Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove data type information from my xml in ruby?

I converted ruby hash data to xml. My xml includes key type such as type="integer"

<problemID type="integer">3</problemID>

How can I remove the type information from my xml? such as the line below

<problemID>3</problemID>

Here is my code which generates xml from hash data.

my_xml = my_hash.to_xml(:root => 'problem')

Thanks alot.

like image 680
500004dolkong Avatar asked Sep 03 '25 08:09

500004dolkong


1 Answers

Use skip_types: true:

my_hash = {problemID: 3}
my_xml = my_hash.to_xml(:root => 'problem', skip_types: true)

puts my_xml
# <?xml version="1.0" encoding="UTF-8"?>
# <problem>
#   <problemID>3</problemID>
# </problem>

From the documentation:

Unless the option :skip_types exists and is true, an attribute “type” is added as well according to the following mapping:

like image 177
Uri Agassi Avatar answered Sep 04 '25 23:09

Uri Agassi