Java XML Node Type containsNodeType(org.w3c.dom.Node node, short nodeType)

Here you can find the source of containsNodeType(org.w3c.dom.Node node, short nodeType)

Description

contains Node Type

License

Open Source License

Declaration

static boolean containsNodeType(org.w3c.dom.Node node, short nodeType) 

Method Source Code

//package com.java2s;
/*/*from  w  ww .  j  ava  2s. co  m*/
 * Copyright (c) 2011 Miguel Ceriani
 * miguel.ceriani@gmail.com
    
 * This file is part of Semantic Web Open datatafloW System (SWOWS).
    
 * SWOWS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
    
 * SWOWS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
    
 * You should have received a copy of the GNU Affero General
 * Public License along with SWOWS.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.NodeList;

public class Main {
    static boolean containsNodeType(org.w3c.dom.Node node, short nodeType) {
        if (node.getNodeType() == nodeType
                || (nodeType == org.w3c.dom.Node.ATTRIBUTE_NODE && node.getAttributes().getLength() > 0))
            return true;
        else {
            NodeList childNodes = node.getChildNodes();
            for (int childIndex = 0; childIndex < childNodes.getLength(); childIndex++)
                if (containsNodeType(childNodes.item(childIndex), nodeType))
                    return true;
        }
        return false;
    }
}

Related

  1. countNodesBefore(Node node, short nodeType)
  2. countNodesBetween(Node node1, Node node2, short nodeType)
  3. getMethodArgValue(final Node typeNode, final String value)
  4. getNodeByType(Node root, int type)