Is there a way to select all the contents of a node?

 ̄綄美尐妖づ 提交于 2019-12-06 14:42:30
shingara
Nokogiri.parse('<root><element>this is <hi>the content</hi> of my element</element></root>').css('element').inner_html

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)
Levi

I think the previous answer is assuming HTML. I'm not sure that's appropriate, so here's my (similar) answer:

require 'nokogiri'
xml = '<root><element>this is <hi>the content</hi> of my æøå element</element></root>' 
p Nokogiri(xml).at('element').to_xml
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!