import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
}
}
- public static Iterable<Element> iterateElements(final NodeList nodes)
+ public static <E extends Node> Iterable<E> iterate(final NodeList nodes, final Class<E> type)
{
- return new Iterable<Element>() {
- public Iterator<Element> iterator() {
- return new NodeListIterator<Element>(nodes, Element.class);
+ return new Iterable<E>() {
+ public Iterator<E> iterator() {
+ return new NodeListIterator<E>(nodes, type);
}
};
}
-
+
static class NodeListIterator<E extends Node>
implements Iterator<E>
{
- Class<?> nodeType_;
+ Class<E> nodeType_;
NodeList nodes_;
int i_ = 0;
E next_;
- public NodeListIterator(NodeList nodes, Class<?> nodeType)
+ public NodeListIterator(NodeList nodes, Class<E> nodeType)
{
nodes_ = nodes;
nodeType_ = nodeType;