Here you can find the source of getTextValue(Element element)
Parameter | Description |
---|---|
element | The element. |
public static String getTextValue(Element element)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; public class Main { private static final int TEXT_CUTOFF = 50; /**/* ww w .java2 s . c om*/ * Returns the text value of an element (title, alt or contents). Note that the result is 50 * characters or less in length. * * @param element * The element. * @return The text value of the element. */ public static String getTextValue(Element element) { String ret = ""; String textContent = element.getTextContent(); if (textContent != null && !textContent.equals("")) { ret = textContent; } else if (element.hasAttribute("title")) { ret = element.getAttribute("title"); } else if (element.hasAttribute("alt")) { ret = element.getAttribute("alt"); } if (ret.length() > TEXT_CUTOFF) { return ret.substring(0, TEXT_CUTOFF); } else { return ret; } } }