Java XML Element Get Value getText(Element element, String name)

Here you can find the source of getText(Element element, String name)

Description

Convenience method to get the first String value with a particular tag name in an XML document element.

License

Open Source License

Declaration

private static String getText(Element element, String name) 

Method Source Code

//package com.java2s;
/* //w  ww. j av a2s.  c  o m
 * File: FileUtil.java
 *
 * Copyright (C) 2010, Dennis Mikkelson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contact : Dennis Mikkelson <mikkelsond@uwstout.edu>
 *           Department of Mathematics, Statistics and Computer Science
 *           University of Wisconsin-Stout
 *           Menomonie, WI 54751, USA
 *
 * This work was supported by the Spallation Neutron Source Division
 * of Oak Ridge National Laboratory, Oak Ridge, TN, USA.
 *
 *  Last Modified:
 * 
 *  $Author:$
 *  $Date:$            
 *  $Revision:$
 */

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**
     *  Convenience method to get the first String value with a particular
     *  tag name in an XML document element. 
     */
    private static String getText(Element element, String name) {
        NodeList node_list = element.getElementsByTagName(name);
        NodeList element_list = ((Element) node_list.item(0)).getChildNodes();
        return (element_list.item(0)).getNodeValue();
    }
}

Related

  1. getText(Element element)
  2. getText(Element element)
  3. getText(Element element)
  4. getText(Element element)
  5. getText(Element element)
  6. getText(Element element, String tagName)
  7. getText(Element node)
  8. getText(final Element el)
  9. getText(final Element element)