使用 Rails 和 Nokogiri 修改具有多个文本的 XML
我正在寻找可以修改 Ruby 中的 .docx
文件的东西。在这里,在这段代码中我对 xml 文件进行了修改。
仅修改一次元素,但想将所有元素 "FirstName"
替换为 "DEMONAME"
doc = Nokogiri::XML(IO.read('word/document.xml'))
doc.at('//text()[.="FirstName"]').content = 'DEMONAME'
File.open('word/document_modify.xml','w') do |f|
f.puts doc
end
请建议修改整个文档 5 次或更多次 名字
。
I am looking for something which will modify the .docx
file in Ruby. Here, in this code I have done with modification in xml file.
Only once element is modified , but wanna replace all the element "FirstName"
with "DEMONAME"
doc = Nokogiri::XML(IO.read('word/document.xml'))
doc.at('//text()[.="FirstName"]').content = 'DEMONAME'
File.open('word/document_modify.xml','w') do |f|
f.puts doc
end
Please suggest some thing to modify whole document having 5 times or more times FirstName
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我找到了解决这个问题的方法。
At last I got the solution to resolve this problem.