Rails:如何使用to_xml方法从ruby哈希生成具有重复节点的xml



我想使用to_XML方法从ruby哈希生成以下XML格式

<commands>
<properties>
<property>
<meta>
<engine>A</engine>
<wheels>4</wheels>
</meta>
<meta>
<engine>B</engine>
<wheels>2</wheels>
</meta>
</property>
</properties>
<schedules/>
<cmds/>
</commands>

标签中有一个<meta>标签,该标签重复两次。使用to_xml方法生成这种格式的哈希应该是什么结构?

我能够通过使用;compare_by_identity"散列方法。使用compare_by_identity方法,我们可以在hash中拥有相同的密钥,这样我就可以在hash中拥有相同密钥,这有助于我创建我在这个问题中发布的XML输出。。

最新更新