Gem 求教 rexml 这个 gem

ptmagic · August 07, 2013 · Last by ptmagic replied at August 07, 2013 · 2750 hits

现在有一个 config.xml 文件,我想往其中插入一个节点,代码如下

requrie 'rexml/document'
require 'rexml/formatters/default'
include REXML

doc = Document.new(File.open("config.xml"),{:raw => :all})
el1 = doc.root.element['device'].add_element 'disk'
el2 = el1.add_element 'qq'

doc.write()

请问为什么我的 xml 没有加入新的节点呢?明明输出 doc 已经加上了啊

自己解决了,原来要用输入输出流导入的 ···ruby file = File.new('config.xml','w+') doc.write( Output.new( file,"UTF-8" ) )

···

You need to Sign in before reply, if you don't have an account, please Sign up first.