From: James Britt Date: 2005-07-07T22:42:46+09:00 Subject: Re: Ruby XPath support (was Re: Extract/Parse String?) Mark Thomas wrote: >>Although that'll work for this particular string, I'd rather think this is a >>case for a HTML parser. Apparently the name of a frame is wanted and a HTML >>parser is the safest way to get that info. > > > Agree completely. Regular expressions should not be used to parse HTML > or XML. However, XPath is an excellent alternative to regular > expressions in these cases. In XPath, the expression to get the name of > the frame would be '//frame/@name'. > > Since I'm new to Ruby, I have to ask: is there an HTML parser that > supports XPath? I know that LibXML does a great job parsing HTML and I > find XPath to be a terrific way to do it--just about anything you want > to extract becomes a one-liner. Do the Ruby bindings expose this > functionality? If not, is there another library that can do this? REXML, part of the standard library, does XPath. If the source HTML is not also XML, then you'll need to coerce it so REXML can load it. Michael Neumann's Mechanize lib bundles up this behavior so that you can grab an HTML doc and operate on select sections; you can also grab the resulting REXML document and run arbitrary XPath calls on it too. Search the ruby-talk archives as this was discussed not too long ago. James > > - Mark. > > > . > -- http://www.ruby-doc.org - The Ruby Documentation Site http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys