From: Henrik Hodne Date: 2009-03-18T22:45:26+09:00 Subject: Re: REXML get specific element Hello, On 18 Mar 2009, at 06:15, Pierre Pat wrote: > All, > > I'm trying for the first time to play with XML and Ruby. > Since I have only the core library at the moment, my choice went > directly for REXML. > > So, here is my problem. > I'm willing to get a specific element in my xml file. > > Normally I would do something like this: > doc.root.elements["programmer[@name='Matz']"] > > But let's say I have a user interface, and I let a user enter the > programmer he wants to see. How can I look for an element using a > variable? > I hoped something like this would work: > entered_name = 'Matz' > doc.root.elements["magician[@name=#{entered_name}]"] > Unfortunately, it didn't... You are missing the '-s. Try doc.root.elements["programmer[@name='#{entered_name}']"] > > > After trying a few things, check with uncle google and in this forum, > I'm driving out of clues, so I'd appreciate if someone could show me > the > correct way! > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > Regards, Henrik Hodne