From: Gavin Kistner Date: 2005-10-11T21:45:20+09:00 Subject: Re: help with htree On Oct 10, 2005, at 2:58 PM, Ara.T.Howard wrote: > i'm trying use the htree library for a relatively simple task in > the hope that > it's parser will outlive one i roll on my own - it certainly seems > robust as > it is... in any case i'm trying to do the following > > - scan a doc for any elements that have a certain attribute > - iff the element with that attribute is of a certain class (b, > i, pre, etc) > then i'll want to replace the text of that element in-place > - finally, a new doc will be produced Not answering your question: why not use regexp? mydoc.gsub( /(myattrname\s*=\s*(?:'#{value}'|"#{value}")[^>]+>[^<]*<(b|i|pre) [^>]*>).*?<\/\\2>/, "\\1#{new_text}" ) (untested) Notable flaw - will fail if the same element is nested within itself.