gpt4 book ai didi

ruby - REXML 格式问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:58:50 25 4
gpt4 key购买 nike

我正在使用 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 添加的是单引号而不是双引号。我通过谷歌找到了以下内容:

  REXML::Attribute.class_eval( %q^
def to_string
%Q[#@expanded_name="#{to_s().gsub(/"/, '"')}"]
end
^ )

我还有一个问题,REXML 正在重新格式化文档。
有办法阻止这种情况吗?

最佳答案

关于引号:版本 3.1.7.3 允许您在元素上使用上下文 cattr_accessor。更新日志:

http://www.germane-software.com/software/rexml/release.html (动态页面)

关于ruby - REXML 格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/833942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com