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!

On Thu, Nov 24, 2011 at 1:49 PM, mythpills p. [email protected]
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!

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

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
}

On Fri, Nov 25, 2011 at 11:39 AM, Mithun P. [email protected]
wrote:

hi robert…thx for guiding me …

YWC

}
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs