Assign new value to node

2019-06-19 20:02栏目:技术创新

require 'delegate'
require 'rexml/text'
require 'rexml/document'

class EntitySubstituter < DelegateClass(IO)
  def initialize(io, document, filter=nil)
    @document = document
    @filter = filter
    super(io)
  end

  def <<(s)
    super(REXML::Text::unnormalize(s, @document.doctype, @filter))
  end
end

str = %{<?xml version='1.0'?>
<!DOCTYPE doc [
 <!ENTITY product 'Stargaze'>
 <!ENTITY version '2.3'>
]>
<doc>
 &product; v&version; 
</doc>}

doc = REXML::Document.new str

text_node = doc.root.children[0]
text_node.value = '&product; v&version;'

doc.write

版权声明:本文由新浦京娱乐站_新浦京娱乐场官网_新浦京娱乐发布于技术创新,转载请注明出处:Assign new value to node