问个用Hpricot解析XML的问题

用Hpricot来解析visual studio的proj文件,想改变当中AddtionalIncludeDirectories的值
用set_attribute设定这项的值,输出的值也确实变了,但原始的aaa.vcproj却没有改变

请教一下,怎么才能改变这个文件呢?


require 'rubygems'
require 'hpricot'

file = open("aaa.vcproj","r+");

doc = Hpricot.XML(file).at("/VisualStudioProject/Configurations")

(doc/:Configuration).each do |config|
  (config/:Tool).each do |tool|
    next unless tool.get_attribute("Name") == "VCCLCompilerTool"
    incdir = tool.get_attribute("AdditionalIncludeDirectories")
    tool.set_attribute("AdditionalIncludeDirectories", incdir << ";"<<".\\dbinc")
    puts tool.get_attribute("AdditionalIncludeDirectories")
  end 
end

file.close

你可能感兴趣的:(xml,rubygems)