【问题标题】:Parsing <first_name>João</first_name> with xml-simple使用 xml-simple 解析 <first_name>João</first_name>
【发布时间】:2010-09-02 21:38:25
【问题描述】:

我在 rake 任务中使用 xml-simple gem 来解析 db 转储的内容。问题是数据库 xml 文件包含导致 xml-simple 崩溃的标题中的字符。有解决办法吗?

【问题讨论】:

    标签: ruby xml xml-simple


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多