首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用nokogiri查看节点的内容?

如何使用nokogiri查看节点的内容?
EN

Stack Overflow用户
提问于 2016-10-17 18:44:41
回答 1查看 43关注 0票数 0
代码语言:javascript
复制
require 'nokogiri'

f = File.open("test.xml")
doc = Nokogiri::XML.parse(f)

description = doc.css('description')

description.each do |item|
    print "#{item}\n"

end

输出:

代码语言:javascript
复制
<description>A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.</description>
<description>An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.</description>
<description>After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.</description>
<description>Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.</description>
<description>The Microsoft MSXML3 parser is covered in 
      detail, with attention to XML DOM interfaces, XSLT processing, 
      SAX and more.</description>
<description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>

如何防止nokogiri撬开<description>标记对?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-17 18:51:03

使用.content方法如下:

代码语言:javascript
复制
require 'nokogiri'

f = File.open("test.xml")
doc = Nokogiri::XML.parse(f)

description = doc.css('description')

description.each do |item|
    print "#{item.content}\n"

end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40093491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档