From: Mike Dalessio Date: 2009-12-16T14:15:53+09:00 Subject: Re: swapping tags & deleting tags via nokogiri --001636417d5fbdcd9e047ad18924 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On Tue, Dec 15, 2009 at 11:55 PM, pablitoman wrote: > > let's say I have an xml document like this > > > > > some text blah blah > > > > > is there a simple method in nokogiri to: > > step 1: convert all tags to something else (e.g.,

) > creating this=85 > > >

> some text blah blah >

>
>
> > step 2: remove all tags but keep the internal tags, creating > this > >

> some text blah blah >

>
> > > I imagine that step 2 is done all the time and there's probably a > simple way to do it, but I'm not sure where to begin with either. > > file =3D Nokogiri::XML(File.new(file_name)) # <=3D this is about as far > as I've gotten (not very...) > > Try Loofah, which is based on Nokogiri: require "loofah" xml =3D <<-eoxml some text blah blah eoxml doc =3D Loofah.xml_document(xml) scrubber =3D Loofah::Scrubber.new do |node| node.name =3D "h1" if node.name =3D=3D "abcde" if node.name =3D=3D "fghij" node.before node.inner_html node.remove end end doc.scrub!(scrubber) puts doc.to_s # =3D> # #

# some text blah blah #

#
--001636417d5fbdcd9e047ad18924--