Problems with text() and REXML

Discussion in 'Ruby' started by Kenneth McDonald, Jan 20, 2009.

  1. I'm finding that in REXML, the XPath selector "//abstract//style"
    correctly selects nodes in the tree, but "//abstract//style//text()"
    does not then extract the text from those nodes. Is this a known
    problem with XPath in Rexml?

    Thanks,
    Ken
     
    Kenneth McDonald, Jan 20, 2009
    #1
    1. Advertising

  2. On 20.01.2009 18:46, Kenneth McDonald wrote:
    > I'm finding that in REXML, the XPath selector "//abstract//style"
    > correctly selects nodes in the tree, but "//abstract//style//text()"
    > does not then extract the text from those nodes. Is this a known
    > problem with XPath in Rexml?


    You're abusing "//". This works for me

    #!/bin/env ruby

    require 'rexml/document'

    doc = REXML::Document.new <<XML
    <root>
    <abstract>
    <style>
    the text
    </style>
    </abstract>
    </root>
    XML

    REXML::XPath.each(doc, '//abstract/style/text()') do |elm|
    p elm
    end

    See also
    http://www.w3schools.com/xpath/
    http://www.zvon.org/xxl/XPathTutorial/General/examples.html

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end
     
    Robert Klemme, Jan 20, 2009
    #2
    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:
    163
    Damphyr
    Jul 16, 2003
  2. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    168
    Henrik Horneber
    Oct 12, 2004
  3. Dan Kohn
    Replies:
    2
    Views:
    211
    Gavin Kistner
    Sep 15, 2005
  4. Marc Hoeppner

    Rexml and some rather basic problems

    Marc Hoeppner, Jan 11, 2008, in forum: Ruby
    Replies:
    2
    Views:
    96
    Marc Hoeppner
    Jan 11, 2008
  5. Phlip
    Replies:
    0
    Views:
    162
    Phlip
    Jan 15, 2008
Loading...

Share This Page