Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Rexml Xpath parsing change

Reply
Thread Tools

Rexml Xpath parsing change

 
 
ermac
Guest
Posts: n/a
 
      10-29-2007
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$

 
Reply With Quote
 
 
 
 
halfgaar@gmx.net
Guest
Posts: n/a
 
      11-03-2007
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/
> 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.


 
Reply With Quote
 
 
 
 
halfgaar@gmx.net
Guest
Posts: n/a
 
      11-03-2007
On Saturday 03 November 2007 21:20, Wiebe Cazemier wrote:

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


I found this:

http://www.intertwingly.net/blog/200...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."



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REXML::Element.write is deprecated. See REXML::Formatters Phlip Ruby 0 01-15-2008 08:23 PM
Parsing through XML with REXML/XPath Peter Bailey Ruby 1 09-25-2007 03:36 PM
rexml error - REXML::Validation Daniel Berger Ruby 2 10-12-2004 04:19 PM
Rexml xpath question Han Holl Ruby 7 03-06-2004 01:23 PM
soap4r 1.4.8.1 with REXML 2.7.1 - no REXML::VERSION_MAJOR Damphyr Ruby 2 07-16-2003 09:49 AM



Advertisments