view raw
InQusitive InQusitive - 7 months ago 38
Ruby Question

Why isn't my Nokogiri working?

This is my first code in ruby using Nokogiri. But it doesn't work and I am not able to understand why.

<?xml version="1.0"?>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<description>An in-depth look at creating applications
with XML.</description>


require 'nokogiri'

f ="test.xml")
doc = Nokogiri::XML(f)
nodes = doc.xpath("title")
nodes.each do |node|
print node.text

Here I am getting the nodes as a nil class.


To select nodes in the document from the current node that match the selection no matter where they are try

nodes = doc.xpath("//title")