我在rake任务中使用xml-simple gem来解析db转储的内容。问题是数据库xml文件包含标题中导致xml-simple崩溃的字符。有没有解决这个问题?
答案 0 :(得分:2)
Nokogiri似乎有效:
require 'nokogiri'
xml =<<ENDOFxML
<test>
<first_name>João</first_name>
</test>
ENDOFxML
doc = Nokogiri::XML.parse(xml)
doc.xpath('//first_name').each do |node|
puts node.inner_text
end
#Output: João