#require 'plist' #require 'ox' require 'rexml/document' class RewritePlistFile # def self.with_prefix(prefix, original) # v = Plist::parse_xml(original) # files = v['files'] # v['files'] = files.map{|i|File.join(prefix, i)} # v.to_plist() # end def self.with_prefix(prefix, original) doc = REXML::Document.new(original) array_element = REXML::XPath.first(doc, "//key[text()='files']/following-sibling::array") array_element.elements.each do |s| s.text = File.join(prefix, s.text) end res = StringIO.new formatter = REXML::Formatters::Pretty.new(2) formatter.compact = true formatter.write(doc, res) return res.string end end