Klaus Hartl wrote:
> I'm confused. You said you don't want to go n level deep. Your query
> would perfectly match "wrong node" now (based on the XML snippet you
> posted and assuming that the outermost unknown node is the root node).
> Anyway, you could write that as:
>
> $('> * > KNOWN_NODE', document.documentElement);
>
> which now looks similiar to the XPATH equivalent:
>
> $('/*/KNOWN_NODE');
>
> I think you have messed up wrong and right in the example
I have been unclear.  The solution you provided worked perfectly for the 
example I gave, but my example was not well-chosen.  The example was 
ambiguous.  Going n levels deep was the very thing I was trying to do 
(match a node of which I know the name and the depth, but don't match 
any nodes with the same name on a different level).

While typing this, I came to a very painful realization: I was wrong all 
along.  The asterisk in CSS is not always deep, it is limited by all 
that precedes it.  So the only difference between my XPath expressions 
and the CSS equivalents is that for CSS, I need to specify the root node 
if I want to match from there.

This works, though for some reason the XPath plugin doesn't translate my 
expressions properly (the expressions you provided in the above quoted 
post return different things).  Here's a new example:

<unknown_node>
  <unknown_node>
    <KNOWN_NODE>right</KNOWN_NODE>
    <unknown_node>
      <KNOWN_NODE>wrong</KNOWN_NODE>
    </unknown_node>
  </unknown_node>
</unknown_node>

$('/*/KNOWN_NODE') matches both KNOWN_NODEs here (with jQuery 1.2.3 and 
the XPath plugin).  I don't know how, but my patch to the XPath plugin 
fixes this behavior.

Hope I haven't confused you even more,

Tim

Reply via email to