PDA

View Full Version : how to select a node containing two children nodes



ruralclimber
16 Jun 2010, 10:23 AM
Hi,

searched a while and could not get a good solution. does anyone know how to use DomQuery (actually it is more about the selector) to select a node with two known children nodes?

for example.


<root>
<level1>
<level2 id="i12" />
<level3 id="i13" />
<level4>this value should be read</level4>
</level1>
<level1>
<level2 id="i22" />
<level3 id="i23" />
<level4>noise</level4>
</level1>
</root>



basically, I want to read this node <level4>this value should be read</level4> if the 'id' for node <level2> is 'i12' AND the 'id' for node <level3> is 'i13'.

I tried the following selector:


root > level1:has(level2[id=i12] and level3[id=i13]) > level4


but it does not work.


Thanks for any suggestions!


best,
Warren

ruralclimber
16 Jun 2010, 12:34 PM
I resolved this issue. maybe someone else is interested on the solution:





Ext.DomQuery.pseudos.hasAll = function(c, selectors) {
var ss = selectors.split('&'),
r = [], ri = -1, s;
for(var i = 0, ci; ci = c[i]; i++){
var match = true;
for(var j = 0; s = ss[j]; j++){
if(Ext.DomQuery.select(s, ci).length<=0){
match=false;
break;
}
}
if(match) {
r[++ri] = ci;
}
}
return r;

}







Hi,

searched a while and could not get a good solution. does anyone know how to use DomQuery (actually it is more about the selector) to select a node with two known children nodes?

for example.


<root>
<level1>
<level2 id="i12" />
<level3 id="i13" />
<level4>this value should be read</level4>
</level1>
<level1>
<level2 id="i22" />
<level3 id="i23" />
<level4>noise</level4>
</level1>
</root>



basically, I want to read this node <level4>this value should be read</level4> if the 'id' for node <level2> is 'i12' AND the 'id' for node <level3> is 'i13'.

I tried the following selector:


root > level1:has(level2[id=i12] and level3[id=i13]) > level4


but it does not work.


Thanks for any suggestions!


best,
Warren