how can i do this ? i need to place tbody after table tags, basically to emulate Firefox's behavior.
i done this:
nodes = @doc.css "table > *"
wrapper = nodes.wrap("<tbody></tbody>")
Thanks.
how can i do this ? i need to place tbody after table tags, basically to emulate Firefox's behavior.
i done this:
nodes = @doc.css "table > *"
wrapper = nodes.wrap("<tbody></tbody>")
Thanks.
<tbody>
should be only be used to wrap the body of your table, so assuming you have no header or footer, this will work:
require 'rubygems'
require 'nokogiri'
html = Nokogiri::HTML(DATA)
html.xpath('//table').each do |htable|
tbody = Nokogiri::XML::Node.new('tbody', html)
htable.children.each do |child|
child.parent = tbody
end
htable.add_child(tbody)
end
puts html.xpath('//table').to_s
__END__
<table border="0" cellspacing="5" cellpadding="5">
<tr><td>Data</td></tr>
<tr><td>Data2</td></tr>
<tr><td>Data3</td></tr>
</table>
prints
<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>