Rexml Xpath parsing change

E

ermac

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/
container1.0.0">
<container name="0001">
<atom name="1001" value="one"/>
<atom name="1002" value="two"/>
<atom name="1003" value="three"/>
</container>
</containerxml>


## Code:

xPath = "/containerxml/container[@name='0001']/atom"
REXML::XPath.each(xDoc.root, xPath) do |elt|
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$
 
H

halfgaar

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/
container1.0.0">
<container name="0001">
<atom name="1001" value="one"/>
<atom name="1002" value="two"/>
<atom name="1003" value="three"/>
</container>
</containerxml>


## Code:

xPath = "/containerxml/container[@name='0001']/atom"
REXML::XPath.each(xDoc.root, xPath) do |elt|
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$

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top