Xpath error

9 views
Skip to first unread message

Luis Miguel Morillas

unread,
Feb 1, 2012, 6:42:43 PM2/1/12
to akar...@googlegroups.com
xml_select raises an error [1] with this xpath sentence:

u'//course[@year=2008 or @year=2010]'

Isn't it a valid xpath sentence?


[1]
[snip] raise RuntimeError("unhandled instruction: %r" % instr)
RuntimeError: unhandled instruction: <instr at 0xa3608ec:
opname='<block 1, offset 0>', oparg=None, target=None>


Saludos,

-- luismiguel

Uche Ogbuji

unread,
Feb 1, 2012, 11:39:26 PM2/1/12
to akar...@googlegroups.com
On Wed, Feb 1, 2012 at 4:42 PM, Luis Miguel Morillas <mori...@gmail.com> wrote:
xml_select raises an error [1] with this xpath sentence:

u'//course[@year=2008 or @year=2010]'

Isn't it a valid xpath sentence?

I think that should be valid. But I don't expect it to ever *work*.

You are comparing an atribute value, always a string, with a number. XPath doesn't do those automatic conversions for you. How about:

u'//course[@year="2008" or @year="2010"]'


--
Uche Ogbuji                       http://uche.ogbuji.net
Weblog: http://copia.ogbuji.net
Poetry ed @TNB: http://www.thenervousbreakdown.com/author/uogbuji/
Founding Partner, Zepheira        http://zepheira.com
Linked-in: http://www.linkedin.com/in/ucheogbuji
Articles: http://uche.ogbuji.net/tech/publications/
Friendfeed: http://friendfeed.com/uche
Twitter: http://twitter.com/uogbuji
http://www.google.com/profiles/uche.ogbuji

Luis Miguel Morillas

unread,
Feb 2, 2012, 1:05:31 AM2/2/12
to akar...@googlegroups.com
Saludos,

-- luismiguel

2012/2/2 Uche Ogbuji <uc...@ogbuji.net>:


> On Wed, Feb 1, 2012 at 4:42 PM, Luis Miguel Morillas <mori...@gmail.com>
> wrote:
>>
>> xml_select raises an error [1] with this xpath sentence:
>>
>> u'//course[@year=2008 or @year=2010]'
>>
>> Isn't it a valid xpath sentence?
>
>
> I think that should be valid. But I don't expect it to ever *work*.
>
> You are comparing an atribute value, always a string, with a number. XPath
> doesn't do those automatic conversions for you. How about:
>
> u'//course[@year="2008" or @year="2010"]'
>
>

Ok. So it is a bug, isn't it? See the complete example:
http://paste2.org/p/1891546

-- lm

> --
> You received this message because you are subscribed to the Google Groups
> "Akara Developers" group.
> To post to this group, send email to akar...@googlegroups.com.
> To unsubscribe from this group, send email to
> akara-dev+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/akara-dev?hl=en.

John L. Clark

unread,
Feb 2, 2012, 10:40:16 AM2/2/12
to akar...@googlegroups.com
On Wed, Feb 1, 2012 at 11:39 PM, Uche Ogbuji <uc...@ogbuji.net> wrote:
> On Wed, Feb 1, 2012 at 4:42 PM, Luis Miguel Morillas <mori...@gmail.com>
> wrote:
>>
>> xml_select raises an error [1] with this xpath sentence:
>>
>> u'//course[@year=2008 or @year=2010]'
>>
>> Isn't it a valid xpath sentence?
>
>
> I think that should be valid. But I don't expect it to ever *work*.
>
> You are comparing an atribute value, always a string, with a number. XPath
> doesn't do those automatic conversions for you.

I'm confused. What about section 3.4 in the spec[0]:

"Otherwise, if at least one object to be compared is a number, then
each object to be compared is converted to a number as if by applying
the number function."

Even so, I thought @year would select the 'year' attribute (and not
its value), so this sentence is more relevant:

"If one object to be compared is a node-set and the other is a number,
then the comparison will be true if and only if there is a node in the
node-set such that the result of performing the comparison on the
number to be compared and on the result of converting the string-value
of that node to a number using the number function is true."

Peace,

John

[0] http://www.w3.org/TR/xpath/#booleans

--
PLEASE NOTE that this message is not digitally signed.  As a result,
you have no strong evidence that this message was actually sent by me.
Upon request I can provide a digitally signed receipt for this
message or other evidence validating its contents if you need such
evidence.

Uche Ogbuji

unread,
Feb 2, 2012, 2:09:13 PM2/2/12
to akar...@googlegroups.com
On Thu, Feb 2, 2012 at 8:40 AM, John L. Clark <jl...@po.cwru.edu> wrote:
On Wed, Feb 1, 2012 at 11:39 PM, Uche Ogbuji <uc...@ogbuji.net> wrote:
> On Wed, Feb 1, 2012 at 4:42 PM, Luis Miguel Morillas <mori...@gmail.com>
> wrote:
>>
>> xml_select raises an error [1] with this xpath sentence:
>>
>> u'//course[@year=2008 or @year=2010]'
>>
>> Isn't it a valid xpath sentence?
>
>
> I think that should be valid. But I don't expect it to ever *work*.
>
> You are comparing an atribute value, always a string, with a number. XPath
> doesn't do those automatic conversions for you.

I'm confused.  What about section 3.4 in the spec[0]:

Nope. Just correct ;)

Good to hear from you John.

 
"Otherwise, if at least one object to be compared is a number, then
each object to be compared is converted to a number as if by applying
the number function."

Yeah I remembered the nodeset conversions but forgot this one. That'll learn me to dash out replies.

 
Even so, I thought @year would select the 'year' attribute (and not
its value), so this sentence is more relevant:

"If one object to be compared is a node-set and the other is a number,
then the comparison will be true if and only if there is a node in the
node-set such that the result of performing the comparison on the
number to be compared and on the result of converting the string-value
of that node to a number using the number function is true."

Right. In any case, it's a bug for it to be throwing a RuntimeError when executing, so I did already have this in mind to investigate. I suspect if we fix the RuntimeError it will behave as the spec says.

Luis if you could prepare a nose test case and open up an issue on GitHub/zepheira/amara, that would be wonderful.

Luis Miguel Morillas

unread,
Feb 2, 2012, 4:05:16 PM2/2/12
to akar...@googlegroups.com
2012/2/2 Uche Ogbuji <uc...@ogbuji.net>:

Sure, I'll send you a bundle next weekend.

-- luismiguel

Reply all
Reply to author
Forward
0 new messages