[英]REXML Formatting issues
我正在使用REXML編輯xml文件,但是在格式化方面遇到了困難。
我的原始代碼如下所示:
file = File.new( destination)
doc = REXML::Document.new file
doc.elements.each("configuration/continuity2") do |element|
element.attributes["islive"] = "true"
element.attributes["pagetitle"] = "#{@client.page_title}"
element.attributes["clientname"] = "#{@client.name}"
end
doc.elements.each("configuration/continuity2/plans") do |element|
element.attributes["storebasedir"] = "#{@client.store_dir}"
end
我首先必須添加以下代碼,因為REXML是添加單引號而不是雙引號。 我通過Google找到了以下內容:
REXML::Attribute.class_eval( %q^
def to_string
%Q[#@expanded_name="#{to_s().gsub(/"/, '"')}"]
end
^ )
我還有一個問題,就是REXML正在重新格式化文檔。
有辦法阻止這種情況嗎?
關於引號:版本3.1.7.3允許您在Element上使用上下文cattr_accessor。 變更日志:
http://www.germane-software.com/software/rexml/release.html (動態頁面)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.