InQusitive InQusitive - 6 days ago 4x
Ruby Question

Why my Nokogiri selector not working?

This is my first attempt using Nokogiri, but it doesn't work and I don't understand why:

This is the XML:

<?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>

I'm using this code:

require 'nokogiri'

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

I am getting the nodes as a nil class.


To select nodes matching the selector try:

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