Here you can find the source of getChildText(Element element, String defaultValue)
Parameter | Description |
---|---|
element | a parameter |
defaultValue | a parameter |
public static String getChildText(Element element, String defaultValue)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { /**// w ww. j a va 2 s. com * Returns the child text of this element, or null if there is none. * @param element * @return String */ public static String getChildText(Element element) { return getChildText(element, null); } /** * Returns the child text of this element, or the default value if there is none. * @param element * @param defaultValue * @return Either the child text of the element or the default value if there is not child text. */ public static String getChildText(Element element, String defaultValue) { Node childNode = element.getFirstChild(); if (childNode == null || !(childNode instanceof Text)) return defaultValue; return childNode.getNodeValue(); } }