Gavin Kistner wrote: > On Jan 23, 3:35 pm, Patrick Callahan <hoc... / youskate.com> wrote: >> I've found an application which dumps all the registry settings for >> installed applications into an .xml file for me (you can find it as >> "myuninstall" via google). >> >> I can't figure out the ruby code I need from REXML to do the following: >> -find a particular "product_name" in the xml file >> -if found, save off the "uninstall_string" so I can execute it on the >> commandline and uninstall the app. > > require 'rexml/document' > doc = REXML::Document.new( DATA.read ) > > # Find 'item' elements at any level > # that have a child 'name' element whose text value is 'foo' > doc.each_element( "//item[name='foo']" ){ |item| > # Find every child element of the item element > # whose name is 'value', get the first one, and get its text > puts item.get_elements( "value" ).first.text > } > #=> 42 > #=> 17 > > __END__ > <root> > <item> > <name>foo</name> > <value>42</value> > </item> > <item> > <name>bar</name> > <value>17</value> > </item> > </root> Wow! That worked on the first try! I knew there had to be a way, but I'm trying to whip this script out and I didn't want to spend a week studying XML parsing options in Ruby to do it. You've saved me a bunch of effort. Now I just need to figure out how to gracefully bail out and continue on with the rest of the script if "foo" isn't there at all. Uhm... I seem to be having trouble with that piece too. I'm sure it's easier than the first problem, but maybe it's just 'cause my brain is cooked right now... Thanks a bunch! -- Posted via http://www.ruby-forum.com/.