Builder GEM XML 格式化

Builder GEM XML formatting

我正在使用 Ruby Gem 生成器,我需要这个输出..

<?xml version="1.0" encoding="utf-8"?>
<fileAttachment> "name of file here.xls"
  <Data>zip</Data>
  <Size>7434</Size>
</fileAttachment>

我的代码在下面,但是 "fileAttachment" 旁边的文件名不起作用。这很简单,我只是没有看到它?错误说我不能将文本与块混合。有道理我只是不知道正确的语法。

 xml = Builder::XmlMarkup.new(:indent => 2 )
 xml.instruct! :xml,:version=>"1.0", :encoding => "utf-8"
   xml.fileAttachment("name of file here.xls") do
     xml.Data "zip"
     xml.Size "7434"
   end

我想你想使用 text! 方法:

xml.fileAttachment do
  xml.text! "name of file here.xls"
  xml.Data "zip"
  xml.Size "7434"
end