Parsing <first_name>João</first_name> with xml-simple
I am using the xml-simple gem inside a rake task to parse the contents of a db dump. The problem is that the database xml file contains characters like those in the title that 开发者_StackOverflowcauses xml-simple to crash. Is there a work around to this?
Nokogiri seems to work:
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
精彩评论