Here you can find the source of getText(Element elem, String ifnull)
public static String getText(Element elem, String ifnull)
//package com.java2s; /*/* w ww . j ava 2s .c o m*/ * Copyright (c) Jim Coles (jameskcoles@gmail.com) 2018 through present. * * Licensed under the following license agreement: * * http://www.apache.org/licenses/LICENSE-2.0 * * Also see the LICENSE file in the repository root directory. */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { public static String getText(Element elem) { return ((Text) elem.getFirstChild()).getData(); } public static String getText(Element elem, String ifnull) { String retVal = null; Node node = elem.getFirstChild(); if (node != null) { if (node.getNodeType() == Node.TEXT_NODE) { retVal = ((Text) node).getData(); } else { System.out.println("Invalid element type in getText()."); } } else { retVal = ifnull; } return retVal; } }