Java XML Node Type getSubnodesOfType(Node in, int type)

Here you can find the source of getSubnodesOfType(Node in, int type)

Description

get Subnodes Of Type

License

Apache License

Parameter

Parameter Description
in non-null Node
type Some note type constant i.e. Node.CDATA_SECTION_NODE

Return

non-null array or children of that type

Declaration

public static Node[] getSubnodesOfType(Node in, int type) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;

import java.util.*;

public class Main {
    /**/*from   www  .j a  v a2  s.  co m*/
    * @param in non-null Node
    * @param type Some note type constant i.e. Node.CDATA_SECTION_NODE
    * @return non-null array or children of that type
    */
    public static Node[] getSubnodesOfType(Node in, int type) {
        NodeList subnodes = in.getChildNodes();
        if (subnodes == null)
            return (new Node[0]);
        int count = subnodes.getLength();
        List holder = new ArrayList();
        for (int i = 0; i < count; i++) {
            Node test = subnodes.item(i);
            if (test.getNodeType() == type)
                holder.add(test);
        }
        Node[] ret = new Node[holder.size()];
        holder.toArray(ret);
        return (ret);
    }
}

Related

  1. getNodesOfType( NamedNodeMap list, short type)
  2. getNodeType(Node node)
  3. getNodeType(Node node)
  4. getNodeType(Node node)
  5. getNodeTypeStr(int nodeType)
  6. getTypeAsString(Node node, boolean cftype)
  7. getTypeName(Node nameNode)
  8. getTypeName(short nodeType)
  9. hasParentNodeType(Node n, String tagToMatch)