This is what I want to do:
Remove the span nodes with the class none.
Delete the extra nodes, but keep the text inside them.
Remove all br nodes and replace them with p nodes
<p class="normal"> <span class="none"> <extra>Some text goes here</extra> </span> <span class="none"> <br/> </span> <span class="none"> <extra>Some other text goes here</extra> <br/> </span> </p>
This is the result that I would like to achieve:
<p class="normal">Some text goes here</p> <p class="normal">Some other text goes here</p>
I have tried this so far:
doc.xpath('html/body/p/span').each do |span| span.attribute_nodes.each do |a| if a.value == "none" span.children.each do |child| span.parent << child end span.remove end end end
But this is the result that I get, not even in the correct order:
<p class="normal"><br /><br />Some text goes hereSome other text goes here</p>
source share