Here you can find the source of getChildNodes(Node parentNode)
Parameter | Description |
---|---|
parentNode | a parameter |
private static ArrayList<Node> getChildNodes(Node parentNode)
//package com.java2s; /*/* w w w.j a v a 2 s .c o m*/ * Copyright IBM Corp. 2011 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ import java.util.ArrayList; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * This method will get the child nodes of a given node and return them in an ArrayList * instead of a NodeList. NodeList does not implement Iterator, which is needed to make * the compare code safer. * @param parentNode * @return an ArrayList of childNodes if the parentNode has childNodes. If there are no children an empty ArrayList is returned. */ private static ArrayList<Node> getChildNodes(Node parentNode) { ArrayList<Node> childNodesArray = new ArrayList<Node>(); if (null != parentNode) { NodeList childNodes = parentNode.getChildNodes(); if (null != childNodes && childNodes.getLength() > 0) { for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (null != child) { childNodesArray.add(child); } } } } return childNodesArray; } }