Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > REXML and XPath

Reply
Thread Tools

REXML and XPath

 
 
Mark Volkmann
Guest
Posts: n/a
 
      01-27-2006
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 =3D 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.


 
Reply With Quote
 
 
 
 
Mark Volkmann
Guest
Posts: n/a
 
      01-27-2006
On 1/26/06, Mark Volkmann <(E-Mail Removed)> 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 =3D XPath.evaluate(doc, count('//book'))


Minor syntax correction here,

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

> There is no "evaluate" method and the "first" and "match" methods don't d=

o this.
>
> Is this supported?


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


 
Reply With Quote
 
 
 
 
Une bévue
Guest
Posts: n/a
 
      01-27-2006
Mark Volkmann <(E-Mail Removed)> 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
 
Reply With Quote
 
Adam Keys
Guest
Posts: n/a
 
      01-27-2006
On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
> On 1/26/06, Mark Volkmann <(E-Mail Removed)> 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://therealadam.com




 
Reply With Quote
 
Mark Volkmann
Guest
Posts: n/a
 
      01-28-2006
On 1/27/06, Adam Keys <(E-Mail Removed)> wrote:
> On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
> > On 1/26/06, Mark Volkmann <(E-Mail Removed)> 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 =3D XPath.evaluate(doc, count('//book'))

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

>
> As a work-around, you could try this:
>
> count =3D 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.


 
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, XPath and Namespace hinsen Ruby 1 06-21-2007 04:55 PM
[newbie] REXML, each_element and XPath Thibaut Barrère Ruby 3 03-08-2006 12:34 PM
rexml error - REXML::Validation Daniel Berger Ruby 2 10-12-2004 04:19 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