descendant

O(1) algorithm to determine if node is descendant of another node in a multiway tree?

北战南征 提交于 2019-12-05 17:20:05
问题 Imagine the following tree: A / \ B C / \ \ D E F I'm looking for a way to query if for example F is a descendant of A (note: F doesn't need to be a direct descendant of A), which, in this particular case would be true. Only a limited amount of potential parent nodes need to be tested against a larger potential descendants node pool. When testing whether a node is a descendant of a node in the potential parent pool, it needs to be tested against ALL potential parent nodes. This is what a came

XPath query with descendant and descendant text() predicates

主宰稳场 提交于 2019-12-03 16:56:16
问题 I would like to construct an XPath query that will return a "div" or "table" element, so long as it has a descendant containing the text "abc". The one caveat is that it can not have any div or table descendants. <div> <table> <form> <div> <span> <p>abcdefg</p> </span> </div> <table> <span> <p>123456</p> </span> </table> </form> </table> </div> So the only correct result of this query would be: /div/table/form/div My best attempt looks something like this: //div[contains(//text(), "abc") and

XPath query with descendant and descendant text() predicates

核能气质少年 提交于 2019-12-03 05:16:09
I would like to construct an XPath query that will return a "div" or "table" element, so long as it has a descendant containing the text "abc". The one caveat is that it can not have any div or table descendants. <div> <table> <form> <div> <span> <p>abcdefg</p> </span> </div> <table> <span> <p>123456</p> </span> </table> </form> </table> </div> So the only correct result of this query would be: /div/table/form/div My best attempt looks something like this: //div[contains(//text(), "abc") and not(descendant::div or descendant::table)] | //table[contains(//text(), "abc") and not(descendant::div

jQuery select descendants, including the parent

有些话、适合烂在心里 提交于 2019-11-29 09:06:25
Consider the following HTML: <div class="foo" id="obj"> I should be changed red <div class="bar" style="color:black;"> I should not be changed red. <div class="foo">I should be changed red.</div> </div> </div> Given a DOM element obj and an expression, how do I go about selecting any children and possibly obj ? I'm looking for something similar to "select descendants" but also including the parent, if it matches the expression. var obj = $("#obj")[0]; //wrong, may include siblings of 'obj' $(".foo", $(obj).parent()).css("color", "red"); //wrong -- excludes 'obj' $(".foo", obj).css("color",

django-mptt get_descendants for a list of nodes

随声附和 提交于 2019-11-29 03:07:35
问题 I am trying to get all descendants(include_self=True) not for one Node, but for a list (a QuerySet) of Nodes. This should be one SQL query. Example (that actually is not working:) some_nodes = Node.objects.filter( ...some_condition... ) some_nodes.get_descendants(include_self=True) #hopefully I would like to have all possible Nodes starting from every node of "some_nodes" The only idea I have right now is to iterate through some_nodes and run get_descendants() for every node - but this is

jQuery select descendants, including the parent

人盡茶涼 提交于 2019-11-28 02:29:24
问题 Consider the following HTML: <div class="foo" id="obj"> I should be changed red <div class="bar" style="color:black;"> I should not be changed red. <div class="foo">I should be changed red.</div> </div> </div> Given a DOM element obj and an expression, how do I go about selecting any children and possibly obj ? I'm looking for something similar to "select descendants" but also including the parent, if it matches the expression. var obj = $("#obj")[0]; //wrong, may include siblings of 'obj' $(