find Next XML Element With Attribute - Android XML

Android examples for XML:XML Attribute

Description

find Next XML Element With Attribute

Demo Code


//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element findNextElementWithAttribute(Node ret,
            String name, String attribute, String value) {
        ret = ret.getNextSibling();/*from   w w  w . java2s . c  om*/
        while (ret != null
                && (!(ret instanceof Element)
                        || !ret.getNodeName().equals(name)
                        || ((Element) ret).getAttribute(attribute) == null || !((Element) ret)
                        .getAttribute(attribute).equals(value))) {
            ret = ret.getNextSibling();
        }
        return (Element) ret;
    }
}

Related Tutorials