On Aug 10, 9:37  尰ᮮ 
> 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 = <<EOF
> <dataformats>
> <dataformat>
> <fileidentifiers>
> <fileidentifier>CFMT</fileidentifier>
> </fileidentifiers>
> </dataformat>
> <dataformat>
> <fileidentifiers>
> <fileidentifier>SPPT</fileidentifier>
> </fileidentifiers>
> </dataformat>
> </dataformats>
> 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')]"