[Htmlparser-developer] NodeIterator and SimpleNodeIterator
Brought to you by:
derrickoswald
|
From: Joseph R. <jmr...@tg...> - 2003-04-02 19:37:38
|
After finding myself poking through more and more of the code for the
HTML parser, and needing to fix bugs, I've decided to join this list.
And I figure that there's no better way to join the list than with a
question. :-) (I've looked through the archives, and I don't see the
answer in there. Sorry if this was discussed before and I missed it.)
Is there a reason that the iterators that Parser.elements() and
CompositeTag.children() are different classes, and are incompatible? I
wanted to write some code along the lines of:
--------------------------------------------------------------
Parser parser = new Parser(url);
NodeIterator iter = parser.elements();
doParse(iter);
...
private void doParse(NodeIterator iter) {
while(iter.hasMoreNodes()) {
Node node = iter.nextNode();
doStuff();
if(node instanceof CompositeTag) {
doParse(((CompositeTag)node).children());
}
}
}
--------------------------------------------------------------
Unfortunately, because the iterators are different (and don't even share
a superclass), I can't do this, and have to duplicate my doParse method
with two different signatures.
This seems like a natural thing to want to do. For example, when
parsing a page, a form tag might contain a lot of other elements (text,
links, etc.) in it that we want to get, and the only way to do that is
to iterate inside.
_____________________________________________________________
Joe Robins Tel: 212-918-5057
Thaumaturgix, Inc. Fax: 212-918-5001
19 W. 44th St., 18th Floor Email: jmr...@tg...
New York, NY 10036 http://www.tgix.com
thau'ma-tur-gy, n. the working of miracles.
|