[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

REXML and XPath

Mark Volkmann

1/27/2006 2:07:00 AM

The documentation for REXML says is has full XPath 1.0 support.
However, I can't see a way to get the XPath class to return values
other than nodes. For example, if I have an XML document that contains
"book" elements, I should be able to do something like this.

count = XPath.evaluate(doc, count('//book'))

There is no "evaluate" method and the "first" and "match" methods don't do this.

Is this supported?

--
R. Mark Volkmann
Partner, Object Computing, Inc.


4 Answers

Mark Volkmann

1/27/2006 2:19:00 AM

0

On 1/26/06, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:
> The documentation for REXML says is has full XPath 1.0 support.
> However, I can't see a way to get the XPath class to return values
> other than nodes. For example, if I have an XML document that contains
> "book" elements, I should be able to do something like this.
>
> count = XPath.evaluate(doc, count('//book'))

Minor syntax correction here,

count = XPath.evaluate(doc, 'count(//book)')

> There is no "evaluate" method and the "first" and "match" methods don't do this.
>
> Is this supported?

--
R. Mark Volkmann
Partner, Object Computing, Inc.


pere.noel

1/27/2006 8:00:00 AM

0

Mark Volkmann <r.mark.volkmann@gmail.com> wrote:

> Minor syntax correction here,
>
> count = XPath.evaluate(doc, 'count(//book)')

does we have to require something else than :
require 'rexml/document'
include REXML


because i get :
NoMethodError: undefined method `evaluate' for REXML::XPath:Class

--
une bévue

Adam Keys

1/27/2006 9:55:00 PM

0

On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
> On 1/26/06, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:
>> The documentation for REXML says is has full XPath 1.0 support.
>> However, I can't see a way to get the XPath class to return values
>> other than nodes. For example, if I have an XML document that
>> contains
>> "book" elements, I should be able to do something like this.
>>
>> count = XPath.evaluate(doc, count('//book'))
>
> Minor syntax correction here,
>
> count = XPath.evaluate(doc, 'count(//book)')
>

As a work-around, you could try this:

count = XPath.match(doc, '//book').length

REXML may just support XPath's selection syntax and not the pseudo-
function-things like you're trying to use above.

--
~akk
http://there...




Mark Volkmann

1/28/2006 1:52:00 PM

0

On 1/27/06, Adam Keys <adam@therealadam.com> wrote:
> On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
> > On 1/26/06, Mark Volkmann <r.mark.volkmann@gmail.com> wrote:
> >> The documentation for REXML says is has full XPath 1.0 support.
> >> However, I can't see a way to get the XPath class to return values
> >> other than nodes. For example, if I have an XML document that
> >> contains
> >> "book" elements, I should be able to do something like this.
> >>
> >> count = XPath.evaluate(doc, count('//book'))
> >
> > Minor syntax correction here,
> >
> > count = XPath.evaluate(doc, 'count(//book)')
> >
>
> As a work-around, you could try this:
>
> count = XPath.match(doc, '//book').length
>
> REXML may just support XPath's selection syntax and not the pseudo-
> function-things like you're trying to use above.

I found out that it does support what I wanted which is XPath
expressions that result in a number, string or boolean. You need to
use the XPath.first method for those.

--
R. Mark Volkmann
Partner, Object Computing, Inc.