Ruby on rails Ruby中的XML解析失败,standalone=";是”;属性(libxml ruby 2.3.3 gem)

Ruby on rails Ruby中的XML解析失败,standalone=";是”;属性(libxml ruby 2.3.3 gem),ruby-on-rails,ruby,libxml2,Ruby On Rails,Ruby,Libxml2,当我运行以下Ruby代码时: xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><project name=\"ProjectA\"/>" parser = XML::Reader.string(xml_str, :encoding => XML::Encoding::UTF_8, :options =>

当我运行以下Ruby代码时:

xml_str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><project name=\"ProjectA\"/>"

parser = XML::Reader.string(xml_str, :encoding => XML::Encoding::UTF_8,
                                :options => ( XML::Parser::Options::NOENT | XML::Parser::Options::NOBLANKS))
parser.read
xml_str=“”
parser=XML::Reader.string(XML\u str,:encoding=>XML::encoding::UTF\u 8,
:options=>(XML::Parser::options::NOENT | XML::Parser::options::NOBLANKS))
parser.read
它抛出一个异常:

Fatal error: Extra content at the end of the document at :1.
LibXML::XML::Error: Fatal error: Extra content at the end of the document at :1.
from (irb):55:in `read'
from (irb):55
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
致命错误:文档末尾的额外内容位于:1。
LibXML::XML::Error:致命错误:文档末尾的额外内容位于:1。
发件人(irb):55:in“read”
起始(irb):55
from/usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in'start'
from/usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in'start'
来自/usr/local/rvm/gems/ruby-2.1.2/gems/railties-3.2.19/lib/rails/commands.rb:41:in`'
来自脚本/rails:6:in'require'
来自脚本/rails:6:in`'
有人能告诉我为什么这个代码会失败吗


注意:如果我删除
standalone=\\“yes\”
或者将XML字符串更改为具有单独的结束元素而不是自动关闭的根标记,那么异常就会消失。

我更喜欢
nokogiri
而不是
libxml ruby
nokogiri
完美地解析了这一点。也许给我一张照片,我不能复制这个,你的代码没有给我一个错误。