开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜