有没有办法选择节点的所有内容?

有没有办法选择Nokogiri中节点的所有内容?

 this is the content of my æøå element  

获取/root/element的内容的结果应该是:

 this is the content of my æøå element 

编辑:

似乎解决方案只是使用myElement.inner_html() 。 我遇到的问题实际上是我依赖于旧版本的libxml2,它逃脱了所有特殊字符。

 Nokogiri.parse('this is the content of my element').css('element').inner_html 

如果你想逃避,你可以使用CGI.unescape方法:

 require 'cgi' x = Nokogiri.parse('this is the content of my element').css('element').inner_html CGI.unescape(x) 

我认为之前的答案是假设HTML。 我不确定这是否合适,所以这是我的(类似)答案:

 require 'nokogiri' xml = 'this is the content of my æøå element' p Nokogiri(xml).at('element').to_xml