Here you can find the source of getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty)
public static String getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty)
//package com.java2s; //License from project: Apache License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String getStringAttributeOptional(Node node, String attributeName, String valueIfEmpty) { NamedNodeMap attributes = node.getAttributes(); Node value = attributes.getNamedItem(attributeName); if (value == null) { return valueIfEmpty; }//from w w w. ja v a 2 s . c om String text = value.getTextContent(); if (text == null) { return valueIfEmpty; } return text; } }