views:

231

answers:

1

I'm using rails and the Nokogiri parser. My 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?

+1  A: 

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

Jonathan Fingland