Java XML Element Get Value getXMLElementTextValue(Element element, String tagName)

Here you can find the source of getXMLElementTextValue(Element element, String tagName)

Description

Parse the text value of the tag with the specified name.

License

Apache License

Parameter

Parameter Description
element , the element to parse from, never <code>null</code>
tagName , the name of the tag, never <code>null</code>

Return

the text value of the tag, null if not exists

Declaration

public static String getXMLElementTextValue(Element element,
        String tagName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {
    /**//from   ww  w.  j a  v  a  2  s  .  co m
     * Parse the text value of the tag with the specified name.
     *
     * @param element
     *            , the element to parse from, never <code>null</code>
     * @param tagName
     *            , the name of the tag, never <code>null</code>
     * @return the text value of the tag, <code>null</code> if not exists
     */
    public static String getXMLElementTextValue(Element element,
            String tagName) {
        NodeList nl = element.getElementsByTagName(tagName);
        if (nl != null && nl.getLength() > 0) {
            Element el = (Element) nl.item(0);
            return el.getFirstChild().getNodeValue();
        }
        return null;
    }
}

Related

  1. getWholeText(Element element)
  2. getXmlBoolean(Element element, String name)
  3. getXMLContent(XMLEventReader reader, StartElement element, boolean decodeCharacters)
  4. getXmlElementAnnotation(Field field)
  5. getXmlElementDecl(Method method)
  6. getXMLIdentifier(Element element)
  7. getXMLText(Element element)