Class ElementCollection

public class ElementCollection
{
  // Constructors
  public ElementCollection(Element root);
  public ElementCollection(Element root, Name tag, int type);

  // Methods
  public Element getChild(int index);
  public int getLength();
  public Object item(String name);
  public Element item(String name, int index);
}

This class provides a collection interface to elements similar to the element collections found in the Internet Explorer 4.0 Dynamic HTML object model.

Constructors

ElementCollection

public ElementCollection(Element root);

Creates new collection object for given element.

ElementCollection

public ElementCollection(Element root, Name tag, int type);

Creates a new collection for iterating over the immediate children of the given root node that have matching tag names and/or element types.

ParameterDescription
rootThe root to form the collection around.
tagThe name of the tag; this parameter can be null if the name is not important.
typeThe element type. Element.ELEMENT is the most common. If the element type is not important, pass -1.

Methods

getChild 

public Element getChild(int index);

Retrieves a specified item from the collection by index.

Return Value

Returns the requested child node; returns null if not found.

ParameterDescription
indexThe index of the item in the element collection.

getLength 

public int getLength();

Retrieves the number of items in the collection.

Return Value

Returns the item count.

item 

public Object item(String name);

Retrieves a named item or a collection of matching items.

Return Value

Returns the requested item. Possible types of objects returned are Element, ElementCollection, or null.

ParameterDescription
nameThe name of the item or collection of matching items.

item 

public Element item(String name, int index);

Retrieves a specified item from the collection of matching items.

Return Value

Returns the requested item if it is found; returns null if it is not found.

ParameterDescription
nameThe name of the matching items.
indexThe index of the specific matching item to return.