Here you can find the source of getChildNodes(Node node, short type)
public static Node[] getChildNodes(Node node, short type)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.List; public class Main { public static Node[] getChildNodes(Node node, short type) { NodeList children = node.getChildNodes(); if (children == null) { return new Node[0]; }//from ww w .j ava 2s.c om int n = children.getLength(); List<Node> elnodelist = new ArrayList<Node>(n); for (int i = 0; i < n; ++i) { Node childnode = children.item(i); if (childnode.getNodeType() == type) { elnodelist.add(childnode); } } Node[] empty = {}; return elnodelist.toArray(empty); } }