Here you can find the source of getElementTextValue(Element in)
Parameter | Description |
---|---|
in | non-null Element |
public static String getElementTextValue(Element in)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; import java.util.*; public class Main { /**//from ww w. j a v a 2 s . com * retrieve text from text from element * @param in non-null Element * @return possibly null text string */ public static String getElementTextValue(Element in) { Node[] testItems = getSubnodesOfType(in, Node.TEXT_NODE); if (testItems.length > 0) return (testItems[0].getNodeValue()); testItems = getSubnodesOfType(in, Node.CDATA_SECTION_NODE); if (testItems.length > 0) return (testItems[0].getNodeValue()); return (null); } /** * @param in non-null Node * @param type Some note type constant i.e. Node.CDATA_SECTION_NODE * @return non-null array or children of that type */ public static Node[] getSubnodesOfType(Node in, int type) { NodeList subnodes = in.getChildNodes(); if (subnodes == null) return (new Node[0]); int count = subnodes.getLength(); List holder = new ArrayList(); for (int i = 0; i < count; i++) { Node test = subnodes.item(i); if (test.getNodeType() == type) holder.add(test); } Node[] ret = new Node[holder.size()]; holder.toArray(ret); return (ret); } }