Short answer: no. You're going to have to do some filtering yourself.

Longer answer: I don't know exactly what your criteria to select some B
elements and not the other. But in any case all it means is that as you
go through the list you need to test and see if the node actually pass
the test that suites you before proceeding.
For instance, if your test is "must be child of A" you can simply do
something like:

NodeList nodes = getElementsByTagName("B", nodeA);
for (int i = 0; i < nodes.getLength(); i++) {
   Node nodeB = nodes.item(i);
   if (nodeB.getParentNode() != nodeA)
       continue;
   ...
}

But actually if all you're looking for is the direct children of A this
is overkilling. You'd better walk through the list of the node's
children. It will be much more efficient:

NodeList nodes = nodeA.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
   Node child = nodes.item(i);
   if (!child.getNodeName().equals("B"))
       continue;
   ...
}
-- 
Arnaud  Le Hors - IBM Cupertino, XML Strategy Group

Reply via email to