while playing with REXML I try to use each_element with an x-path
expression involving an attribute (doc/element/@attribute) but can't
get it to work this way (it works perfectly fine with both XPath.each
and each_element applied on doc/element without @attribute).
here's my test suite to illustrate this, is there some obvious mistake
that I cannot see ? I've read in older posts that each_element did not
recurse, would it be the explanation ?
any insight most welcome!
kind regards
Thibaut
···
============
require "test/unit"
require "rexml/document"
include REXML
Not sure if this is a bug. I'm using the version of REXML that comes
with 1.8.2 on Windows.
Farrel
···
On 3/8/06, Thibaut Barrère <thibaut.barrere@gmail.com> wrote:
Hi!
while playing with REXML I try to use each_element with an x-path
expression involving an attribute (doc/element/@attribute) but can't
get it to work this way (it works perfectly fine with both XPath.each
and each_element applied on doc/element without @attribute).
here's my test suite to illustrate this, is there some obvious mistake
that I cannot see ? I've read in older posts that each_element did not
recurse, would it be the explanation ?
any insight most welcome!
kind regards
Thibaut
============
require "test/unit"
require "rexml/document"
include REXML
I've done some experimentation and I think the problem is as follows.
/doc/element/@attribute is a search for the attribute node, not the
element, so using it with doc.each_element isn't strictly
'semantically' correct. If you want to find an element with an
attribute you should use the /doc/element[@attribute] xpath string.