Phlip
11/10/2007 3:12:00 PM
Charles Sword wrote:
> I've used REXML to write both tree and stream parsers for simple xml
> files but I can't seem to return values for the xml below in either
> case:
>
> <HIT NO="1" RANK="15335" SITEID="0" MOREHITS="0" FCOCOUNT="0">
> <FIELD NAME="title">Sample Text</FIELD>
> </HIT>
>
> In this example I'd like to return the value (Sample Text)for the <FIELD
> NAME="title"> tag? So my question is how do I specify this attribute to
> either a tree or stream parser?
Use XPath:
title = REXML::XPath.first(doc, '/HIT/FIELD[ "title" = @name ]').text
Look up my assert_xpath project for more XPath scenarios.
--
Phlip