Java XML Child Node Get getChildNodes(Node node, short type)

Here you can find the source of getChildNodes(Node node, short type)

Description

get Child Nodes

License

Open Source License

Declaration

public static Node[] getChildNodes(Node node, short type) 

Method Source Code

//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);
    }
}

Related

  1. getChildNodes(final Node node, short... types)
  2. getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames)
  3. getChildNodes(Node node)
  4. getChildNodes(Node node)
  5. getChildNodes(Node node)
  6. getChildNodes(Node node, String name)
  7. getChildNodes(Node parent, String childName)
  8. getChildNodes(Node parentNode)
  9. getChildNodes(Node parentNode, String childName)