From: anne001 Date: 2008-08-11T08:42:46+09:00 Subject: Re: Using XPath to retrieve an XML element which contains a given text Thank you, the first formulation works. I had tried the second one on the complete xml file and it does not work. Do you have an idea why? Is there a typo I am not seeing? Here is a test file a little closer to the XML file I am working with require "rexml/document" include REXML string = < NARSAD recognition NARSAD SPFT SPFT SPPT EOF doc = Document.new string xpathquery="//dataformat[contains(., 'SPPT')]" p 'yours1' p XPath.first(doc,xpathquery).to_s xpathquery="//dataformat[contains(fileidentifiers/ fileidentifier,'SPPT')]" p 'yours2' p XPath.first(doc,xpathquery).to_s result "yours1" "\n\t\tSPFT\n\t\t\n\t\t \tSPFT\n\t\t\tSPPT\n\t\t\n\t" "yours2" ""