javax.swing.text.HTMLDocument getIterator returns null for some Tags

From: Jim Cobban (jcobban_at_magma.ca)
Date: 11/19/04


Date: Fri, 19 Nov 2004 12:53:47 -0500

I have encountered a problem which is reported multiple times in this
discussion group, and over in .programmer as well. That is that
HTMLDocument.getIterator mysteriously returns a null value for some tag
types, while working, equally mysteriously, for other tag types. In all
cases instead of responses addressing the problem itself the user has been
advised of some more or less obscure workaround.

The problem reports go back over 8 years, and since HTMLDocument.getIterator
continues to behave in the same way, I must assume that it is operating as
designed. However if it is so, then why has the documentation not been
updated to reflect that the intent is that getIterator will return null for
some tag types, and with a list of those tag types for which it does work
added to the documentation?

Obviously whoever wrote the code did so to solve some specific requirement,
and as soon as it had addressed that requirement the code was shoved to the
back burner. It certainly is a peculiar interface, since a normal iterator
mechanism provides access to the components that are being iterated over,
whereas this interface provides access only to some, not all, of the
information that would be available if the iterator provided access to the
Elements themselves. But then the entire HTMLDocument interface seems
clumsy and poorly thought out compared to the XML DOM and SAX interfaces.
The XML DOM interface, by contrast, provides clear standarized ways to get
to and iterate over particular tag types and the attributes under them,
which are not provided by the HTMLDocument interface. This forces every
developer to reinvent the wheel, which is contrary to the philosophy
espoused in the Java API as a whole.

I just wish that the documentation warned users not to waste time trying to
use getIterator where it is not going to work. Certainly if the community
has no intention of making getIterator work for all tag types, not just some
mysterious and undocumented subset, then the method should at least be
deprecated.



Relevant Pages

  • Re: javax.swing.text.HTMLDocument getIterator returns null for some Tags
    ... > I have encountered a problem which is reported multiple times in this ... > types, while working, equally mysteriously, for other tag types. ... It certainly is a peculiar interface, since a normal iterator ...
    (comp.lang.java.gui)
  • Re: Virtual Iterators
    ... > Classes A and B both conform to the same abstract Interface class. ... > virtual VirtualIterator begin{return ... > copy of the real iterator. ...
    (comp.lang.cpp)
  • Re: comparison of objects
    ... the standard function is being used versus your redefinition. ... User's interface would give means to iteration, ... ** User and implementor interface: ... An iterable is an object for which an iterator can be defined. ...
    (comp.lang.lisp)
  • Re: Forevery() writable iterator mechanism in C# 3
    ... The '_itr_mth' LLP tag means 'Iterator Method'. ... Why would the interface need ref/out itself? ... A destructive operation will by definition be refelected in all references ... collection at all - that's really a major point of "yield", ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Forevery() writable iterator mechanism in C# 3
    ... Currently you can not pass ref and out arguments to an iterator ... Why would the interface need ref/out itself? ... A destructive operation will by definition be refelected in all references ... collection at all - that's really a major point of "yield", ...
    (microsoft.public.dotnet.languages.csharp)