doc.xpath("//tbody").remove
removes tbody's children ! i only want to remove all tags from the document !
how can i achieve this ?
doc.xpath("//tbody").remove
removes tbody's children ! i only want to remove all tags from the document !
how can i achieve this ?
require 'rubygems'
require 'nokogiri'
html = Nokogiri::HTML(DATA)
html.xpath('//table/tbody').each do |tbody|
tbody.children.each do |child|
child.parent = tbody.parent
end
tbody.remove
end
puts html.xpath('//table').to_s
__END__
<table border="0" cellspacing="5" cellpadding="5"><tbody>
<tr><td>Data</td></tr>
<tr><td>Data2</td></tr>
<tr><td>Data3</td></tr>
</tbody></table>
prints
<table border="0" cellspacing="5" cellpadding="5">
<tr><td>Data</td></tr>
<tr><td>Data2</td></tr>
<tr><td>Data3</td></tr>
</table>