Direct Child Selector BAD Behaviour

6 views
Skip to first unread message

dario....@gmail.com

unread,
Dec 5, 2016, 11:46:05 AM12/5/16
to support-querypath
Consider this simple markup (list):

<html>
   
<body>
 

     
<div class=mz-block" id="block-1">
             
<ul>
                   
<li class="branch">
                       
<u>MENU 1</u>
                       
<ul>
                           
<li class="leaf">foo1</li>
                           
<li class="leaf">foo2</li>
                           
<li class="branch">foo3
                               
<ul>
                                   
<li class="leaf">foo4</li>
                                   
<li class="leaf">foo5</li>
                                   
<li class="branch">foo6
                                       
<ul>
                                           
<li class="leaf">foo7</li>
                                       
</ul>
                                   
</li>
                               
</ul>
                           
</li>
                           
<li class="leaf">foo8</li>
                       
</ul>
                   
</li>
               
</ul>
     
</div>

     
<div class=mz-block" id="block-2">
         ...
     
</div>

     
<div class=mz-block" id="block-3">
         ...
     
</div>


   
</body>
</html>



Let's sat that i want to print ONLY the 4th <li> element of 2nd "descendant line".. so:

<li class="leaf">foo8</li>


In jQuery i will do like this:

console.log( $('div.mz-block').eq(0).find('> ul > li > ul > li').eq(3).html() );


And it works fine...
But, if i try the same in QueryPath, like this:

print html5qp($HTMLdoc,'div.mz-block')->eq(0)->find('> ul > li > ul > li')->eq(3)->html5();


i get this (wrong) element

<li class="leaf">foo4</li>

Which is (obviously) NOT a "direct" descendant ....


Finally, i tried with an XPath expression, so:

print $HTMLdoc->xpath('/html/body/div[@class="mz-block"]')->eq(0)->xpath('ul/li/ul/li')->eq(3)->html5();


And it works properly... output:

<li class="leaf">foo8</li>

...........

Any ideas???
Is there a way to report this "problem" directly to the Author?








TechnoSophos

unread,
Dec 5, 2016, 11:49:12 AM12/5/16
to support-querypath
That is a bug. It should return foo8.

When you have a moment, can you file that in the issue queue. 

--
You received this message because you are subscribed to the Google Groups "support-querypath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to support-queryp...@googlegroups.com.
To post to this group, send email to support-...@googlegroups.com.
Visit this group at https://groups.google.com/group/support-querypath.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages