Here you can find the source of getChildNodes(final Node node, final short nodetype)
Parameter | Description |
---|---|
node | parent. |
nodetype | searched child type. |
public static List<Node> getChildNodes(final Node node, final short nodetype)
//package com.java2s; /**// w w w. j av a 2 s . co m * Copyright ? Microsoft Open Technologies, Inc. * * All Rights Reserved * * 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 * * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT. * * See the Apache License, Version 2.0 for the specific language * governing permissions and limitations under the License. */ import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Gets the given node's children of the given type. * * @param node parent. * @param nodetype searched child type. * @return children. */ public static List<Node> getChildNodes(final Node node, final short nodetype) { final List<Node> result = new ArrayList<Node>(); final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child.getNodeType() == nodetype) { result.add(child); } } return result; } }