From: Dejan Dimic Date: 2008-08-11T07:07:56+09:00 Subject: Re: Using XPath to retrieve an XML element which contains a given text On Aug 10, 9:37 pm, anne001 wrote: > This code returns the first dataformat element. > And yet the second dataformat is the one containing SPPT. > What am I doing wrong? > > require "rexml/document" > > include REXML > > string = <   >       >                 >                         CFMT >                 >         >       >                 >                         SPPT >                 >       >   > EOF > > doc = Document.new string > xpathquery="//dataformat[contains(fileidentifier, SPPT)]" > p XPath.first(doc,xpathquery).to_s I think you XPath query should be: xpathquery="//dataformat[contains(., 'SPPT')]" or more specific one: xpathquery="//dataformat[contains(fileidentifiers/ fileidentifier,'SPPT')]"