rake
对于为什么我的任务不会创建所需的 XML 文件,我有点迷失了,但是当我build_xml
在.rb
文件中有方法时它可以正常工作。
require 'rubygems'
require 'nokogiri'
require 'open-uri'
namespace :xml do
desc "xml build test"
task :xml_build => :environment do
build_xml
end
end
def build_xml
# build xml docoument
builder = Nokogiri::XML::Builder.new do |xml|
xml.root {
xml.location {
xml.value "test"
}
}
end
File.open("test.xml", 'w') {|f| f.write(builder.to_xml) }
end