On Tue, 11 Oct 2005, Gavin Kistner wrote: > 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}" > ) i already have a working version. i just wanted to learn htree. it's very robust and context sensitive. > (untested) > > Notable flaw - will fail if the same element is nested within itself. a big flaw for parsing hierarchical text no? ;-) my solution doesn't handle nesting either - though it could quite easily : it's a mini/dumb parser. cheers. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================