Java tutorial
//package com.java2s; /* * 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 { /** * Helper Method. Searches through the child nodes of a node and returns the first node with a matching name. * Do we need this ? * @param element The node to read from * @param nodeName String The name of the node * @param caseSensitive If true, the node name searcher will be case sensitive * @return Node the located node or null if one was not found */ public static Node getChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive) { if (element == null) return null; if (nodeName == null) return null; final String name = nodeName.toString().trim(); if (name.isEmpty()) return null; 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 node; } else { if (node.getNodeName().equalsIgnoreCase(name)) return node; } } return null; } /** * Helper Method. Case insensitive. Searches through the child nodes of a node and returns the first node with a matching name. * Do we need this ? * @param element The node to read from * @param name The name of the child node * @return Node the located node or null if one was not found */ public static Node getChildNodeByName(Node element, CharSequence name) { return getChildNodeByName(element, name, false); } }