Here you can find the source of hasChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive)
Parameter | Description |
---|---|
element | The node to inspect |
nodeName | The name of the child node to look for |
caseSensitive | true for a case sensitive node, false for case insensitive |
public static boolean hasChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive)
//package com.java2s; /*/*from w ww . j av a 2s . co m*/ * Copyright 2015 the original author or authors. * * 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 org.w3c.dom.*; public class Main { /** * Indicates if the passed node has a child node of the passed name * @param element The node to inspect * @param nodeName The name of the child node to look for * @param caseSensitive true for a case sensitive node, false for case insensitive * @return true if the named child node exists, false otherwise */ public static boolean hasChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive) { if (element == null) return false; if (nodeName == null) return false; final String name = nodeName.toString().trim(); if (name.isEmpty()) return false; NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (caseSensitive) { if (node.getNodeName().equals(name)) return true; } else { if (node.getNodeName().equalsIgnoreCase(name)) return true; } } return false; } }