From: William James Date: 2006-08-24T06:00:07+09:00 Subject: Re: (RE)XML question rubyhacker@gmail.com wrote: > Question for you all. I want to treat HTML like XML > (which is no big deal). > > But I want to find certain "special" tags (not real > HTML) and replace them with my own text. > > It's macro-type stuff. Basically I want to output > the *same* HTML except for the text that replaced > the special tags. > > I can't find any examples of generating XML with > REXML. It should be easy, I don't want it to be > too hard. > > Contrived example below in case it helps. > > How would you do this? > > Thanks, > Hal > > > Input: > > > >

Hi, there.

> some more text >

That's all.

> > > > Output: > > >

Hi, there.

>

I found a foo tag enclosing 'some more text' with > bar and bam values of 'this' and 'that'...

>

That's all.

> > require 'xml-split.rb' tag = 'foo' DATA.read.xml_split(tag).each {|stuff| if stuff.class == String print stuff else attr = stuff[0].xml_parse puts "

I found a #{tag} tag enclosing '#{stuff[1]}' with" print "#{attr.keys.join(' and ')} values of " print "'#{attr.values.join("' and '")}'...

" end } __END__

Hi, there.

some more text

That's all.

---- output ----

Hi, there.

I found a foo tag enclosing 'some more text' with bam and bar values of 'that' and 'this'...

That's all.