require 'rexml/document'
str = File.readlines('myxml.xml').join # '<a></a>'
el = REXML::Document.new str
p el.to_s # "<a/>"我想要<a></a>而不是<a />。我如何在ruby中使用rexml实现这个功能呢?
发布于 2017-03-15 19:15:05
因为它是XML,所以元素被折叠,除非有可能嵌套的emply节点:
el.root.add_text ''
el.to_s
#⇒ "<a></a>"https://stackoverflow.com/questions/42807782
复制相似问题