Java XML Element Get Value getTextList(Element elem, String name)

Here you can find the source of getTextList(Element elem, String name)

Description

get Text List

License

Open Source License

Declaration

public static List<String> getTextList(Element elem, String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

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

public class Main {

    public static List<String> getTextList(Element elem, String name) {
        List<String> result = new ArrayList<String>();
        List<Element> childElements = getChildElementsByTagName(elem, name);
        for (Element childElem : childElements) {
            Node node = childElem.getFirstChild();
            result.add(node == null ? "" : node.getTextContent());
        }//www .j av  a 2s  . c  om
        return result;
    }

    public static List<Element> getChildElementsByTagName(Element elem, String name) {
        List<Element> result = new ArrayList<Element>();
        NodeList nodeList = elem.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node child = nodeList.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(name)) {
                result.add((Element) child);
            }
        }
        return result;
    }
}

Related

  1. getTextContents(Element e)
  2. getTextData(Element element)
  3. getTextElementValue(Element ele)
  4. getTextFromFirstSubEleByName(Element element, String tagName)
  5. getTextFromTag(Element current, String tag)
  6. getTextOfElement(Element e)
  7. getTexts(Element root, String elementName)
  8. getTextString(Element e)
  9. getTextTrim(Element element)