开发者

How can XmlSimple output XML just like data.to_xml?

Can XmlSimple.xml_out output XML the same way to_xml does? (instead of attributes, use tags):

> puts XmlSimple.xml_out([{'a' => 1, 'b' => 3.3}])
<opt>
  <anon a="1" b="3.3" />
</opt>

> puts ([{:a => 1, :b => 3.3}].to_xml)
<?xml version="1.0" encoding="UTF-8"?>
<records type="array">
  <record>
    <b type="float">3.3</b>
    <a type="integer">1</a>
  </recor开发者_StackOverflow社区d>
</records>


From the fine manual:

NoAttr => true | false (in + out) (handy)
When used with xml_out, the generated XML will contain no attributes. All hash key/values will be represented as nested elements instead.

When used with xml_in, any attributes in the XML will be ignored.

I think you want:

XmlSimple.xml_out([{'a' => 1, 'b' => 3.3}], 'NoAttr' => true)

That should give you something closer to what to_xml does but you won't get the type attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜