Java XML Element Get Value getTextFromTag(Element current, String tag)

Here you can find the source of getTextFromTag(Element current, String tag)

Description

Return the inner text from the given tag

License

Open Source License

Parameter

Parameter Description
current the current element
tag the tag name

Return

the text inside the tag, or ""

Declaration

private static String getTextFromTag(Element current, String tag) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published by

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**/*ww w . ja va 2  s  .  com*/
     * Return the inner text from the given tag
     * 
     * @param current
     *            the current element
     * @param tag
     *            the tag name
     * @return the text inside the tag, or ""
     */
    private static String getTextFromTag(Element current, String tag) {
        if (current == null)
            return "";
        String result = "";
        NodeList nodes = current.getElementsByTagName(tag);
        if (nodes.getLength() > 0)
            result = ((Element) nodes.item(0)).getTextContent();
        return result;
    }
}

Related

  1. getTextContentOfElements(Element elem, String tagName)
  2. getTextContents(Element e)
  3. getTextData(Element element)
  4. getTextElementValue(Element ele)
  5. getTextFromFirstSubEleByName(Element element, String tagName)
  6. getTextList(Element elem, String name)
  7. getTextOfElement(Element e)
  8. getTexts(Element root, String elementName)
  9. getTextString(Element e)