找到你要的答案

Q:Nokogiri return empty array parsing an xml file

Q:锯返回空数组解析XML文件

Nothing worked when I tried the first time, so i decided to try with the exemple given by nokogiri I took their xml doc listing some characters of sitcoms:

Edit : After having read the comment it seems that it comes from an issue of my environment or something like that specific to me : 2.2.0p0 nokogiri : 1.6.6.2

[demo.xml]
<root>
  <sitcoms>
    <sitcom>
      <name>Married with Children</name>
      <characters>
        <character>Al Bundy</character>
        <character>Bud Bundy</character>
        <character>Marcy Darcy</character>
      </characters>
    </sitcom>
    <sitcom>
      <name>Perfect Strangers</name>
      <characters>
        <character>Larry Appleton</character>
        <character>Balki Bartokomous</character>
      </characters>
    </sitcom>
  </sitcoms>
  <dramas>
    <drama>
      <name>The A-Team</name>
      <characters>
        <character>John "Hannibal" Smith</character>
        <character>Templeton "Face" Peck</character>
        <character>"B.A." Baracus</character>
        <character>"Howling Mad" Murdock</character>
      </characters>
    </drama>
  </dramas>
</root>
require 'nokogiri'


@doc = Nokogiri::XML(File.open("demo.xml"))
@doc.xpath("//character")

and runned ruby test.rb but this gave no results but no error so i tried the same in irb which returned me

 => [] 

I'm sure it's something silly but I have no clue and i'm not finding the answer anywhere (that's why i'm thinking that's silly) :) Thx to you

没有工作的时候,我第一次尝试,所以我决定尝试给出的锯我把他们的XML文档清单情景喜剧的一些特性的例:

编辑:看评论似乎来自我的环境或类似的东西,具体到我的问题后,2.2.0p0锯:1.6.6.2

[demo.xml]
<root>
  <sitcoms>
    <sitcom>
      <name>Married with Children</name>
      <characters>
        <character>Al Bundy</character>
        <character>Bud Bundy</character>
        <character>Marcy Darcy</character>
      </characters>
    </sitcom>
    <sitcom>
      <name>Perfect Strangers</name>
      <characters>
        <character>Larry Appleton</character>
        <character>Balki Bartokomous</character>
      </characters>
    </sitcom>
  </sitcoms>
  <dramas>
    <drama>
      <name>The A-Team</name>
      <characters>
        <character>John "Hannibal" Smith</character>
        <character>Templeton "Face" Peck</character>
        <character>"B.A." Baracus</character>
        <character>"Howling Mad" Murdock</character>
      </characters>
    </drama>
  </dramas>
</root>
require 'nokogiri'


@doc = Nokogiri::XML(File.open("demo.xml"))
@doc.xpath("//character")

跑了红宝石test.rb但这没有结果,但没有错误,所以我试着同样的IRB返回我

 => [] 

我确信这是愚蠢的东西,但我不知道,我没有找到答案的地方(这就是为什么我认为这是愚蠢的):)谢谢你

ruby  nokogiri  screen-scraping