Here you can find the source of getNodeValue(Node fatherNode, String nodeName)
Parameter | Description |
---|---|
fatherNode | the parent node |
nodeName | name of the wanted child node |
public static String getNodeValue(Node fatherNode, String nodeName)
//package com.java2s; /**//w w w. j av a2 s.c om * Copyright 2008 - 2009 Pro-Netics S.P.A. * * 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.Element; import org.w3c.dom.Node; public class Main { /** * Gets a node's text value given its parent node and the name of the wanted child node.<br> * * @param fatherNode the parent node * @param nodeName name of the wanted child node * @return String text node value */ public static String getNodeValue(Node fatherNode, String nodeName) { String value = null; if (((Element) fatherNode).getElementsByTagName(nodeName) != null) { Node node = ((Element) fatherNode).getElementsByTagName(nodeName).item(0); value = node.getTextContent(); if (value != null) { value = value.trim(); } } return value; } /** * Gets the node value * * @param node Node * @return String node value */ public static String getNodeValue(Node node) { String value = null; if (node.getFirstChild() != null) { value = node.getFirstChild().getNodeValue(); } return value; } }