Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > REXML XPath bug?

Reply
Thread Tools

REXML XPath bug?

 
 
Andy Watts
Guest
Posts: n/a
 
      05-14-2008
I'm having trouble with a particular XPATH in REXML and would greatly
appreciate any help.

Given this simple document..
<body>
<div class="summary">xxx</div>
<div>
<span>yyy</span>
</div>
</body>

The xpath "//div[@class='summary']/following-sibling::div/span" is
failing to return '<span>yyy</span>'.


Here's a console dump that also shows a simplier xpath working.

>> REXML::XPath.match(doc, "//div[@class='summary']/following-sibling::div/span").to_s

=> ""
>> REXML::XPath.match(doc, "//div[@class='summary']/following-sibling::div").to_s

=> "<div>\n<span>yyy</span>\n</div>"
>> puts doc.to_s

<body>
<div class='summary'>xxx</div>
<div>
<span>yyy</span>
</div>
</body>

The xpath works fine in firefox's xpath checker, so it seems like an
issue with rexml.
Any help greatly appreciated.

- Andy
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Casimir
Guest
Posts: n/a
 
      05-17-2008
On Wed, 14 May 2008 15:00:47 -0500, Andy Watts wrote:

> I'm having trouble with a particular XPATH in REXML and would greatly
> appreciate any help.

(rest of it quoted below)

Ok, I tested this with JEdits XPATH tool and indeed, the xpath "//div
[@class='summary']/following-sibling::div" returns the span-element with
string-value yyy, xml fragment <span>yyy</span>.

Is it a bug? I must admit I would need to read more references etc before
being able to say definately - or is it just different interpretation of
the following-sibling -axis. Dont have the time to see the rfc atm.

But I played around a bit:
irb(main):046:0> puts root.elements["//div[@class='summary']/following-
sibling::div/span"]
nil
* So, it doesnt work like that.

irb(main):047:0> puts root.elements["//div[@class='summary']/following-
sibling::div"]
<div>
<span>yyy</span>
</div>
* hmm....

irb(main):049:0> puts root.elements["//div[@class='summary']/
following::div/span"]
<span>yyy</span>
** Would this work in your case?

ALSO - you could include the rexml namespace by adding the line
include REXML
after the rexml requires. This way you wont have to use the long ::-
syntax, but can refer to document or elements directly, and use xpaths
simply as above inside [""].

I also played around with this http://www.zvon.org:9001/saxon/cgi-bin/
XLab/XML/xpatut_15.html and following seems to accomplish what you need.

Finally, just plain-jane /div/span would select the span but maybe there
can be many and you only want the one after the summary div.

Out of time, gtg

Casimir Pohjanraito

> Given this simple document..
> <body>
> <div class="summary">xxx</div>
> <div>
> <span>yyy</span>
> </div>
> </body>
>
> The xpath "//div[@class='summary']/following-sibling::div/span" is
> failing to return '<span>yyy</span>'.
>
>
> Here's a console dump that also shows a simplier xpath working.
>
>>> REXML::XPath.match(doc,
>>> "//div[@class='summary']/following-sibling::div/span").to_s

> => ""
>>> REXML::XPath.match(doc,
>>> "//div[@class='summary']/following-sibling::div").to_s

> => "<div>\n<span>yyy</span>\n</div>"
>>> puts doc.to_s

> <body>
> <div class='summary'>xxx</div>
> <div>
> <span>yyy</span>
> </div>
> </body>
>
> The xpath works fine in firefox's xpath checker, so it seems like an
> issue with rexml.
> Any help greatly appreciated.
>
> - Andy


 
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
rexml error - REXML::Validation Daniel Berger Ruby 2 10-12-2004 04:19 PM
[BUG?] NoMethodError in REXML::Xpath.match in Ruby 1.9 Alexey Verkhovsky Ruby 0 08-03-2004 05:51 AM
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57