/***** Code de MesExemples.com *******/
import org.w3c.dom.Attr;import org.w3c.dom.Element;public class Utils { /** * Returns null, not "", for a nonexistent attribute. * * @param e * @param attributeName * @return */ public static String getAttributeValueEmptyNull(Element e, String attributeName) { Attr node = e.getAttributeNode(attributeName); if (node == null) { return null; } return node.getValue(); }}
Code testé avec le fichier XML Suivant
Sakoba
Adams
Rappel
Ne m'oubliez pas ce week-end!