librelist archives

« back to archive

issues using preceding-sibling/following-sibling in xpath queries

issues using preceding-sibling/following-sibling in xpath queries

From:
Bryant Fong
Date:
2010-06-02 @ 21:02
I'm having trouble getting sibling-based xpath queries to work with
search(), which seem to work fine in an xpath validator.  It works if I use
at() and then call following_siblings on the element returned, but I am
calling hpricot through a wrapper (scrubyt) and thus don't have that option.

Simple example:

1) Go to hpricot.com
2) In the frame on the right, type http://news.google.com/ and an arbitrary
xpath query that should work like "//div[5]/following-sibling::*"

No results are returned.  I think that the xpath validator is invalidating
the query.  What stupid thing am I doing this time?

Or am I talking to an empty list :-)..

Thanks!

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
i5m
Date:
2010-06-03 @ 12:27
Bryant,

I think it's going to be bad news. Just had a quick check with Hpricot 0.8.2
on Windows, but with Ruby 1.8.7, 1.9.1 and JRuby 1.5.

Doing the following:

doc = Hpricot(open("http://news.google.com/"))
doc.search("//div/table") #works, returns results
doc.search("//div/child::table") #returns no results, although is apparently
equivalent according to
http://wiki.github.com/hpricot/hpricot/supported-xpath-expressions

Tried with a few other "supported axes", couldn't get any to work. I don't
think this xpath functionality is in Hpricot, or if it is, it's broken.

If I get a chance I'll try and check on OSX as well, just to make sure it's
not a Windows thing.
-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Wed, Jun 2, 2010 at 10:02 PM, Bryant Fong <bryantf@gmail.com> wrote:

> I'm having trouble getting sibling-based xpath queries to work with
> search(), which seem to work fine in an xpath validator.  It works if I use
> at() and then call following_siblings on the element returned, but I am
> calling hpricot through a wrapper (scrubyt) and thus don't have that option.
>
> Simple example:
>
> 1) Go to hpricot.com
> 2) In the frame on the right, type http://news.google.com/ and an
> arbitrary xpath query that should work like "//div[5]/following-sibling::*"
>
> No results are returned.  I think that the xpath validator is invalidating
> the query.  What stupid thing am I doing this time?
>
> Or am I talking to an empty list :-)..
>
> Thanks!
>
>

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
i5m
Date:
2010-06-03 @ 12:32
One option would be looking to see if you can do what you want with
Mechanize directly. E.g:


http://stackoverflow.com/questions/1298080/transitioning-from-scrubyt-to-nokogiri-write-to-xml-or-hash


<http://stackoverflow.com/questions/1298080/transitioning-from-scrubyt-to-nokogiri-write-to-xml-or-hash>
-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Thu, Jun 3, 2010 at 1:27 PM, i5m <i5ivem@gmail.com> wrote:

> Bryant,
>
> I think it's going to be bad news. Just had a quick check with Hpricot
> 0.8.2 on Windows, but with Ruby 1.8.7, 1.9.1 and JRuby 1.5.
>
> ...
> Tried with a few other "supported axes", couldn't get any to work. I don't
> think this xpath functionality is in Hpricot, or if it is, it's broken.
>
>
>
>
> On Wed, Jun 2, 2010 at 10:02 PM, Bryant Fong <bryantf@gmail.com> wrote:
>
>> I'm having trouble getting sibling-based xpath queries to work with
>> search(), which seem to work fine in an xpath validator.
>>
>>
>
>

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
Bryant Fong
Date:
2010-06-03 @ 18:58
Hmm, thats what I was afraid of.  Strange.  Do you know what underlying
xpath library hpricot uses?  Anyways, big thanks for getting back to me -- I
know I can go direct, but it means I have to write more code instead of
using existing wrapper libraries.  Oh well..

On Thu, Jun 3, 2010 at 5:32 AM, i5m <i5ivem@gmail.com> wrote:

> One option would be looking to see if you can do what you want with
> Mechanize directly. E.g:
>
>
> 
http://stackoverflow.com/questions/1298080/transitioning-from-scrubyt-to-nokogiri-write-to-xml-or-hash
>
>
> 
<http://stackoverflow.com/questions/1298080/transitioning-from-scrubyt-to-nokogiri-write-to-xml-or-hash>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>
>
>  On Thu, Jun 3, 2010 at 1:27 PM, i5m <i5ivem@gmail.com> wrote:
>
>> Bryant,
>>
>> I think it's going to be bad news. Just had a quick check with Hpricot
>> 0.8.2 on Windows, but with Ruby 1.8.7, 1.9.1 and JRuby 1.5.
>>
>> ...
>>  Tried with a few other "supported axes", couldn't get any to work. I
>> don't think this xpath functionality is in Hpricot, or if it is, it's
>> broken.
>>
>>
>>
>>
>>  On Wed, Jun 2, 2010 at 10:02 PM, Bryant Fong <bryantf@gmail.com> wrote:
>>
>>> I'm having trouble getting sibling-based xpath queries to work with
>>> search(), which seem to work fine in an xpath validator.
>>>
>>>
>>
>>
>

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
i5m
Date:
2010-06-04 @ 10:34
Well the readme says " The XPath and CSS parser, in fact, is based on John
Resig's JQuery." So basically it's using it's own custom xpath library.
Whereas Nokogiri uses libxml2.


-----------------------
i5m.co.uk
GPG Key: 0xA18A602B


On Thu, Jun 3, 2010 at 7:58 PM, Bryant Fong <bryantf@gmail.com> wrote:

> Hmm, thats what I was afraid of.  Strange.  Do you know what underlying
> xpath library hpricot uses?  Anyways, big thanks for getting back to me -- I
> know I can go direct, but it means I have to write more code instead of
> using existing wrapper libraries.  Oh well..
>
>

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
Bryant Fong
Date:
2010-06-04 @ 21:37
Just to complete this thread, it works as expected in Nokogiri.

It is listed as supported in the hpricot wiki (
http://wiki.github.com/hpricot/hpricot/supported-xpath-expressions), but it
could be because I'm using hpricot 0.8.5.  I think they're at 1.0 now, which
isn't compatible with scrubyt.  So, I'll probably be switching over to
Nokogiri instead which appears to be more active.  Thanks for your help once
again.
On Fri, Jun 4, 2010 at 3:34 AM, i5m <i5ivem@gmail.com> wrote:

> Well the readme says " The XPath and CSS parser, in fact, is based on John
> Resig's JQuery." So basically it's using it's own custom xpath library.
> Whereas Nokogiri uses libxml2.
>
>
> -----------------------
> i5m.co.uk
> GPG Key: 0xA18A602B
>
>
>  On Thu, Jun 3, 2010 at 7:58 PM, Bryant Fong <bryantf@gmail.com> wrote:
>
>> Hmm, thats what I was afraid of.  Strange.  Do you know what underlying
>> xpath library hpricot uses?  Anyways, big thanks for getting back to me -- I
>> know I can go direct, but it means I have to write more code instead of
>> using existing wrapper libraries.  Oh well..
>>
>>
>

Re: [hpricot] issues using preceding-sibling/following-sibling in xpath queries

From:
i5m
Date:
2010-06-02 @ 22:28
Bryant,

On 2 Jun 2010, at 22:02, Bryant Fong <bryantf@gmail.com> wrote:

> Or am I talking to an empty list :-)..

Not empty, but I suspect not overflowing. I shall try to take a look  
tomorrow.

(Disclaimer: Not involved in Hpricot in any official capacity, but I  
do quite like it)