REXML and XPath

Discussion in 'Ruby' started by Mark Volkmann, Jan 27, 2006.

  1. 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.
     
    Mark Volkmann, Jan 27, 2006
    #1
    1. Advertising

  2. On 1/26/06, Mark Volkmann <> 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.
     
    Mark Volkmann, Jan 27, 2006
    #2
    1. Advertising

  3. Mark Volkmann

    Une bévue Guest

    Mark Volkmann <> 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
     
    Une bévue, Jan 27, 2006
    #3
  4. Mark Volkmann

    Adam Keys Guest

    On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
    > On 1/26/06, Mark Volkmann <> 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
     
    Adam Keys, Jan 27, 2006
    #4
  5. On 1/27/06, Adam Keys <> wrote:
    > On Jan 26, 2006, at 8:18 PM, Mark Volkmann wrote:
    > > On 1/26/06, Mark Volkmann <> 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.
     
    Mark Volkmann, Jan 28, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damphyr
    Replies:
    2
    Views:
    148
    Damphyr
    Jul 16, 2003
  2. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    158
    Henrik Horneber
    Oct 12, 2004
  3. Thibaut Barrère

    [newbie] REXML, each_element and XPath

    Thibaut Barrère, Mar 8, 2006, in forum: Ruby
    Replies:
    3
    Views:
    134
    Thibaut Barrère
    Mar 8, 2006
  4. hinsen

    REXML, XPath and Namespace

    hinsen, Jun 16, 2007, in forum: Ruby
    Replies:
    1
    Views:
    112
    Keith Fahlgren
    Jun 21, 2007
  5. Phlip
    Replies:
    0
    Views:
    151
    Phlip
    Jan 15, 2008
Loading...

Share This Page