我有以下代码用于从rabl模板生成xml:
obj = OpenStruct.new
obj.categories = [{node: ["Foo","Bar"]},{node: ["Test1","Test2"]}]
Rabl::Renderer.xml(obj, 'adapter_xml')
这是rabl模板adapter_xml.rabl
object @obj => :root
attributes :categories
生成此XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<categories>
<category>
<node>
<node>Foo</node>
<node>Bar</node>
</node>
</category>
<category>
<node>
<node>Test1</node>
<node>Test2</node>
</node>
</category>
</categories>
</root>
但我想要实现的是以下格式,没有额外的<node>
标签:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<categories>
<category>
<node>Foo</node>
<node>Bar</node>
</category>
<category>
<node>Test1</node>
<node>Test2</node>
</category>
</categories>
</root>
有没有办法用rabl做到这一点?或者我是否必须修改首先提到的ruby代码?