>Can you please help me find out about "traversal" mechanisms?
http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113/
>I need a way to get a list of all subelemenents
>(direct children) of an element that have a given tagname.
The DOM spec has some examples of the use of TreeWalker and NodeIterator.
They may be overkill for your example. It might be more efficient, but it
would also probably be significantly more coding effort. (Traversal's real
win comes when you want to be able to pass several different "filtered
views" through the same kind of processing, or when the filtering is more
complex.)
If you wanted to do this via the traversal tools, you could set up a
TreeWalker with whatToShow set to SHOW_ELEMENTS, and a NodeFilter plugged
into that which accepted only the nodes having the name you were interested
in, and navigate that "filtered view" of the document.
Or you could do the same thing with a NodeIterator, but there the
NodeFilter would have to explicitly say not to expand elements or you'd
wind up doing a deep search again.
Personally, since this is such a simple query, I'd probably just loop
through the children and test 'em myself:
for (Node n=myparentelement.getFirstChild();
n!=null;
n=n.getNextSibling() )
{
if(givenTagname.equals(n.getNodeName()))
{
...process it, or add to a list for later processing...
}
}
(Note: You said "tag name", so that's what I've coded. But these days you
should probably be writing namespace-aware code, and checking localname and
namespace URI rather than tagname.)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]