有没有办法选择一个节点的所有内容? [英] Is there a way to select all the contents of a node?
本文介绍了有没有办法选择一个节点的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以选择Nokogiri中节点的所有内容?
Is there a way to select all the contents of a node in Nokogiri?
<root>
<element>this is <hi>the content</hi> of my æøå element</element>
</root>
获取/root/element
内容的结果应该是:
The result of getting the content of /root/element
should be:
this is <hi>the content</hi> of my æøå element
似乎解决方案就是简单地使用myElement.inner_html()
.实际上,我遇到的问题是我依靠的是旧版本的libxml2,该版本转义了所有特殊字符.
It seems like the solution is simply to use myElement.inner_html()
. The problem I had was in fact that I was relying on an old version of libxml2, which escaped all the special characters.
推荐答案
Nokogiri.parse('<root><element>this is <hi>the content</hi> of my element</element></root>').css('element').inner_html
如果要转义,可以使用CGI.unescape
方法:
If you want escape that, you can with CGI.unescape
method:
require 'cgi'
x = Nokogiri.parse('<root><element>this is <hi>the content</hi> of my element</element></root>').css('element').inner_html
CGI.unescape(x)
这篇关于有没有办法选择一个节点的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文