Java: Retourner nul pour un attribut non-existant*

Author:

Java: Retourner nul pour un attribut non-existant*
Download

/***** 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

<?xml version="1.0" encoding="windows-1252"?>
<!-- Edited by MesEXemple.com -->
<note>
	<to>Sakoba</to>
	<from>Adams</from>
	<heading>Rappel</heading>
	<body>Ne m'oubliez pas ce week-end!</body>
</note>

Cet article Java: Retourner nul pour un attribut non-existant* est apparu en premier sur .