开发者

Finding a text node in xml using xpath problem

I'm using rails and the Nokogiri parser. My 开发者_StackOverflow中文版xml is as below and I'm trying to get the 'Biology: 08:00' text into my view.

 <rss version="2.0">
      <channel>
        <item>
          <title>Biology: 08:00</title>
          <description>Start time of Biology</description>
          <pubDate>Tue, 13 Oct 2009 UT</pubDate>
        </item>
       </channel>
    </rss>

I can find the node with the text 'biology' using the code below

@content = doc.xpath('//title[contains(text(),"Biology")]')

When I move it into my view it strangely ends up as the title of my .html.erb page. I can't seem to get it into the body with

<body>
<%=@content%>
</body>

anyone know what's going on?


You're getting the whole node, and the node is a <title> tag.

you want:

@content = doc.xpath('//title[contains(text(),"Biology")]/text()')   

to get the text content of the node

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜