I think this is the string interpolation you're looking for: root.elements["foo/bar[#{i}]"].text Paul.