get Offspring from XML Node - Java XML

Java examples for XML:XML Node

Description

get Offspring from XML Node

Demo Code


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main{
    /**//from w  w w  . ja v  a 2s  .co  m
     * 
     * @param node
     * @param name
     * @return null if has't find the node
     */
    public static Node getOffspring(Node node, String name) {
        NodeWalker walker = new NodeWalker(node);
        Node result = null;
        while (walker.hasNext()) {
            Node n = walker.nextNode();
            if (n.getNodeName().equalsIgnoreCase(name)) {
                result = n;
                break;
            }
        }
        return result;
    }
}

Related Tutorials