这是我第一次使用Nokogiri,但是它不起作用,我也不明白为什么:
这是XML:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
</catalog>
我正在使用此代码:
require 'nokogiri'
f = File.open("test.xml")
doc = Nokogiri::XML(f)
nodes = doc.xpath("title")
nodes.each do |node|
print node.text
end
我将节点作为nil类。
要选择与选择器匹配的节点,请尝试:
nodes = doc.xpath("//title")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句