Suppose that we have XML -
And we need to remove <genre> tag but keep the inside that tag -
We can achieve this with Nokogiri -
xml_content = <?xml version="1.0"?> <book> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book>
And we need to remove <genre> tag but keep the inside that tag -
<?xml version="1.0"?> <book> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> Computer <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book>
We can achieve this with Nokogiri -
require 'nokogiri' doc = Nokogiri::XML 'xml_content' doc.xpath('//genre').each do |tag| tag.replace(Nokogiri::XML::Text.new(tag.text, tag.document)) end doc.inner_html