REXML XPath question

J

Ja Ha

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'> ... </>]
 
J

Ja Ha

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top