Converts a w3c DOM XML nodelist into an iterator. - Android XML

Android examples for XML:DOM

Description

Converts a w3c DOM XML nodelist into an iterator.

Demo Code

/***************************************
 *            ViPER                    *
 *  The Video Processing               *
 *         Evaluation Resource         *
 *                                     *
 *  Distributed under the GPL license  *
 *        Terms available at gnu.org.  *
 *                                     *
 *  Copyright University of Maryland,  *
 *                      College Park.  *
 ***************************************/
//package com.java2s;

import java.util.*;
import org.w3c.dom.*;

public class Main {
    /**/*from w w  w  .j  a va 2  s.c  om*/
     * Converts a w3c DOM nodelist into an iterator.
     * @param nl the node list
     * @return the iterator wrapping the list of DOM nodes
     */
    public static Iterator nodeList2Iterator(final NodeList nl) {
        final int[] i = new int[] { 0 };
        return new Iterator() {
            public boolean hasNext() {
                return i[0] < nl.getLength();
            }

            public Object next() {
                return nl.item(i[0]++);
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
}

Related Tutorials