DhEnumeration Class

DhEnumeration Class

This Package | All Packages

public class DhEnumeration
implements IEnumerator

Represents a collection of elements in the HTML document. You can either create a DhEnumeration object class directly (using new()) or call DhDocument.enumerate to get the collection.

Note As of this Beta release, there are only three types of collections: ELEMENTS, IMAGES, and HLINKS.

Many HTML tags do not map one-to-one to Java classes in this package. When enumerating through the return of next(), always check the result with an instanceof() call.

Fields
Name Description
ELEMENTS Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all elements on the page.
HLINKS Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all link (A) elements on the page.

IMAGES Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all Image (IMG) elements on the page.

Constructors
Name Description
DhEnumeration( DhDocument document, int enumType ) Creates a DhEnumeration object.

Methods
Name Description
hasMoreItems() Tests if this enumeration contains more elements.
next() Returns the next element of this enumeration.
nextItem() Returns the next element of this enumeration.
reset() Resets the enumerator to the beginning.

Fields

DhEnumeration.ELEMENTS

Syntax
public static final int ELEMENTS;
Description
Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all elements on the page.

DhEnumeration.HLINKS

Syntax
public static final int HLINKS;
Description
Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all link (A) elements on the page.

DhEnumeration.IMAGES

Syntax
public static final int IMAGES;
Description
Used by either DhDocument.enumerate or the DhEnumeration constructor to indicate a collection of all Image (IMG) elements on the page.

Constructors

DhEnumeration.DhEnumeration

Syntax
public DhEnumeration( DhDocument document, int enumType );
Parameters
document
A reference to a DhDocument.
enumType
One of the legal types of collections (ELEMENTS, IMAGES, or HLINKS).
Description

Creates a DhEnumeration object. You can use this constructor or call DhDocument.enumerate to get the collection.

Methods

DhEnumeration.hasMoreItems

Syntax
public synchronized boolean hasMoreItems();
Return Value

Returns true if this enumeration contains more elements; otherwise, returns false.

Description

Tests if this enumeration contains more elements.

DhEnumeration.next

Syntax
public synchronized DhElement next();
Return Value

Returns the next element of this enumeration, or returns null if one does not exist.

Description

Returns the next element of this enumeration. This override of IEnumerator.next() returns a DhElement object so there is no need to cast the result to a DhElement object. The result can be further cast (for example, to DhImage) depending on the type of enumeration this is.

Many HTML tags do not map one-to-one into Java classes in this package. When enumerating through the return of next(), always check the result with an instanceof() call.

DhEnumeration.nextItem

Syntax
public Object nextItem();
Return Value

Returns the next element of this enumeration.

Description

Returns the next element of this enumeration.

Exceptions

NoSuchElementException thrown if no more elements exist.

See Also
next

DhEnumeration.reset

Syntax
public void reset();
Description

Resets the enumerator to the beginning.