# Rexml Xpath parsing change

**URL:** <https://rubytalk.org/t/rexml-xpath-parsing-change/41759>\
**Category:** ruby-talk\
**Created:** [29 October 2007 19:25 UTC](https://rubytalk.org/t/rexml-xpath-parsing-change/41759 "2007-10-29T19:25:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ermac](https://avatars.discourse-cdn.com/v4/letter/e/838e76/32.png) [@ermac](https://rubytalk.org/u/ermac)\
**Post date:** [29 October 2007 19:25 UTC](https://rubytalk.org/t/rexml-xpath-parsing-change/41759/1 "2007-10-29T19:25:11Z")

</div>

Hi,

Some of my old code no longer works with the latest version of ruby  
and I'm trying to figure out why.

My code is parsing an XML file with REXML, using XPath.each(). The  
same code with the same xpath on the same xml input returns some  
results in ruby 1.8.4, but no results in ruby 1.8.6.

Can anyone explain this? I've had no luck searching through the  
archives of this group.

I've distilled out a minimal example.

## XML input:

\<?xml version="1.0" encoding="UTF-8"?\>  
\<containerxml version="2" xmlns="[http://www.frogbender.com/schemas/](http://www.frogbender.com/schemas/)  
container1.0.0"\>  
&nbsp;&nbsp;&nbsp;&nbsp;\<container name="0001"\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1001" value="one"/\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1002" value="two"/\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1003" value="three"/\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</container\>  
\</containerxml\>

## Code:

xPath = "/containerxml/container[@name='0001']/atom"  
REXML::XPath.each(xDoc.root, xPath) do |elt|  
&nbsp;&nbsp;&nbsp;&nbsp;puts elt.attributes["name"]  
end

## Results on ruby 1.8.4:

build4:/p4/gq$ ruby -v  
ruby 1.8.4 (2005-12-24) [i586-linux]

build4:/p4/gq$ ruby test.rb  
1001  
1002  
1003

## Results on ruby 1.8.6:

jim@roch:/tmp$ ruby -v  
ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]

jim@roch:/tmp$ ruby test.rb  
jim@roch:/tmp$

---

<div class="post-metadata">

**Author:** ![Wiebe\_Cazemier](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@Wiebe\_Cazemier](https://rubytalk.org/u/Wiebe_Cazemier)\
**Post date:** [3 November 2007 20:20 UTC](https://rubytalk.org/t/rexml-xpath-parsing-change/41759/2 "2007-11-03T20:20:16Z")

</div>

Did you find a solution? I'm having the same problem.

> **···**
>
> On Monday 29 October 2007 20:25, ermac wrote:
> 
> > Hi,
> > 
> > Some of my old code no longer works with the latest version of ruby  
> > and I'm trying to figure out why.
> > 
> > My code is parsing an XML file with REXML, using XPath.each(). The  
> > same code with the same xpath on the same xml input returns some  
> > results in ruby 1.8.4, but no results in ruby 1.8.6.
> > 
> > Can anyone explain this? I've had no luck searching through the  
> > archives of this group.
> > 
> > I've distilled out a minimal example.
> > 
> > ## XML input:
> > 
> > \<?xml version="1.0" encoding="UTF-8"?\>  
> > \<containerxml version="2" xmlns="[http://www.frogbender.com/schemas/](http://www.frogbender.com/schemas/)  
> > container1.0.0"\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;\<container name="0001"\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1001" value="one"/\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1002" value="two"/\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<atom name="1003" value="three"/\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;\</container\>  
> > \</containerxml\>
> > 
> > ## Code:
> > 
> > xPath = "/containerxml/container[@name='0001']/atom"  
> > REXML::XPath.each(xDoc.root, xPath) do |elt|  
> > &nbsp;&nbsp;&nbsp;&nbsp;puts elt.attributes["name"]  
> > end
> > 
> > ## Results on ruby 1.8.4:
> > 
> > build4:/p4/gq$ ruby -v  
> > ruby 1.8.4 (2005-12-24) [i586-linux]
> > 
> > build4:/p4/gq$ ruby test.rb  
> > 1001  
> > 1002  
> > 1003
> > 
> > ## Results on ruby 1.8.6:
> > 
> > jim@roch:/tmp$ ruby -v  
> > ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]
> > 
> > jim@roch:/tmp$ ruby test.rb  
> > jim@roch:/tmp$

---

<div class="post-metadata">

**Author:** ![Wiebe\_Cazemier](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@Wiebe\_Cazemier](https://rubytalk.org/u/Wiebe_Cazemier)\
**Post date:** [3 November 2007 20:44 UTC](https://rubytalk.org/t/rexml-xpath-parsing-change/41759/3 "2007-11-03T20:44:08Z")

</div>

I found this:

[http://www.intertwingly.net/blog/2007/11/02/MonkeyPatch-for-Ruby-1-8-6](http://www.intertwingly.net/blog/2007/11/02/MonkeyPatch-for-Ruby-1-8-6)

A quote from the article:

"Unfortunately, there is a bug in Ruby 1.8.6 that affects documents with a  
default namespace (even a vestigial one, like those sported by WordPress  
weblogs) which prevents non-namespace qualified attribute names from working  
in XPath expressions."

> **···**
>
> On Saturday 03 November 2007 21:20, Wiebe Cazemier wrote:
> 
> > Did you find a solution? I'm having the same problem.
