REXML XPath question

Discussion in 'Ruby' started by Ja Ha, Jun 25, 2007.

  1. Ja Ha

    Ja Ha Guest

    Can anyone explain these result to me (see bottom)?

    require 'rexml//document'
    d = REXML::Document.new %{
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="uniq"
    xml:lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"
    />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <title>test</title>
    </head>
    <body>
    <p id="foo">3</p>
    <p id="bar">4</p>
    <div id="div">
    <p id="baz" foo:attr="here">5</p>
    <p id="bat" class="wag">6</p>
    </div>
    </body>
    </html>
    }

    REXML::XPath.match d, "/html/body/p[@id='foo']"
    #-> []

    REXML::XPath.match d, "/html/body/p[@id]"
    #-> []

    REXML::XPath.match d, "/html/body/p[@*]"
    #-> [<p id='foo'> ... </>, <p id='bar'> ... </>]

    --
    Posted via http://www.ruby-forum.com/.
    Ja Ha, Jun 25, 2007
    #1
    1. Advertising

  2. Ja Ha

    Ja Ha Guest

    OK I just removed xmlns="http://www.w3.org/1999/xhtml" from the <html>
    tag (the default namespace) and now it works.

    Is this a bug?

    --
    Posted via http://www.ruby-forum.com/.
    Ja Ha, Jun 25, 2007
    #2
    1. Advertising

  3. Ja Ha

    Ja Ha Guest

    Wow, 2 replies from myself...

    I just found out that XPath 1.0 does not work correctly with a default
    namespace. So this is "correct" behavior.



    --
    Posted via http://www.ruby-forum.com/.
    Ja Ha, Jun 25, 2007
    #3
    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:
    128
    Damphyr
    Jul 16, 2003
  2. Han Holl

    Rexml xpath question

    Han Holl, Feb 22, 2004, in forum: Ruby
    Replies:
    7
    Views:
    129
    Han Holl
    Mar 6, 2004
  3. Alexey Verkhovsky
    Replies:
    0
    Views:
    162
    Alexey Verkhovsky
    Aug 3, 2004
  4. Daniel Berger

    rexml error - REXML::Validation

    Daniel Berger, Oct 12, 2004, in forum: Ruby
    Replies:
    2
    Views:
    136
    Henrik Horneber
    Oct 12, 2004
  5. Phlip
    Replies:
    0
    Views:
    131
    Phlip
    Jan 15, 2008
Loading...

Share This Page