Here you can find the source of getNodeContent(Node item, String nodeName)
public static Optional<String> getNodeContent(Node item, String nodeName)
//package com.java2s; //License from project: Open Source License import java.util.Optional; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* w ww . ja va 2s .c om*/ * Gets the content of a subnode. * For example, * <item> * <nodeName>content</nodeName> * </item> */ public static Optional<String> getNodeContent(Node item, String nodeName) { if (item.getNodeType() != Node.ELEMENT_NODE) { return Optional.empty(); } NodeList metadata = ((Element) item).getElementsByTagName(nodeName); if (metadata.getLength() == 1) { return Optional.ofNullable(metadata.item(0).getTextContent()); } else { return Optional.empty(); } } }