Here you can find the source of getSimpleElementText(final Element element, final String nodeName)
Parameter | Description |
---|---|
element | a parameter |
nodeName | a parameter |
public static String getSimpleElementText(final Element element, final String nodeName)
//package com.java2s; /******************************************************************************* * Manchester Centre for Integrative Systems Biology * University of Manchester/*from www .j a va2 s. co m*/ * Manchester M1 7ND * United Kingdom * * Copyright (C) 2007 University of Manchester * * This program is released under the Academic Free License ("AFL") v3.0. * (http://www.opensource.org/licenses/academic.php) *******************************************************************************/ import org.w3c.dom.*; import org.w3c.dom.Element; public class Main { /** * * @param element * @param nodeName * @return String */ public static String getSimpleElementText(final Element element, final String nodeName) { final Element namedElement = getFirstElement(element, nodeName); if (namedElement != null) { return getSimpleElementText(namedElement); } return null; } /** * * @param node * @return String */ public static String getSimpleElementText(final Node node) { final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child instanceof Text) { return child.getNodeValue(); } } return null; } /** * * @param element * @param nodeName * @return Element */ public static Element getFirstElement(final Element element, final String nodeName) { final NodeList list = element.getElementsByTagName(nodeName); if (list.getLength() == 0) { return null; } return (Element) list.item(0); } }