Check if a element with a specific value exists in a xml using REXML

i have attached a sample xml. I am currently using REXML ..basically i
want to check if a element with a specific value exists in XML using our
REXML processor?
for e.g. lets say i want to find if there is a node which holds this
value => "content/t1/st_4/page2.swf" and return true (as a node does
exist in the attached xml with the above value)

Help!

Attachments:
http://www.ruby-forum.com/attachment/6787/main.xml

···

--
Posted via http://www.ruby-forum.com/.

http://www.w3schools.com/xpath/
http://www.zvon.org/xxl/XPathTutorial/General/examples.html

e.g.

//file[text()="content/t1/st_4/page2.swf"]

Btw, nokogiri is usually faster than REXML.

Kind regards

robert

···

On Thu, Nov 24, 2011 at 1:49 PM, mythpills p. <mithunpillay@gmail.com> wrote:

i have attached a sample xml. I am currently using REXML ..basically i
want to check if a element with a specific value exists in XML using our
REXML processor?
for e.g. lets say i want to find if there is a node which holds this
value => "content/t1/st_4/page2.swf" and return true (as a node does
exist in the attached xml with the above value)

Help!

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

hi robert..thx for guiding me ..

i found a way out in rexml though...wntd 2 share with you..

foundnode = "no"
xmldoc.elements.each("course/file"){ |element|
      nod = "content/t1/st_4/page2.swf"
      if element.text == nod
         foundnode = "yes"
      else
       foundnode = "no"
      end
      }

···

--
Posted via http://www.ruby-forum.com/.

hi robert..thx for guiding me ..

YWC

i found a way out in rexml though...wntd 2 share with you..

foundnode = "no"
xmldoc.elements.each("course/file"){ |element|
nod = "content/t1/st_4/page2.swf"
if element.text == nod
foundnode = "yes"
else
foundnode = "no"
end
}

Just be careful: variable foundnode cannot be used as a boolean
because in Ruby any String is considered "true".

Also, I don't understand why you do not use the XPath.

Kind regards

robert

···

On Fri, Nov 25, 2011 at 11:39 AM, Mithun P. <pillay.mithun@gmail.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/