Returns null, not "", for a nonexistent attribute : DOM Attribute « XML « Java






Returns null, not "", for a nonexistent attribute

  

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();
  }

}

   
    
  








Related examples in the same category

1.Get all the attributes for an Element
2.Get attribute's value
3.Return the right attribute node
4.Return the value of the attribute of the given element with the given name
5.Output XML element Attributes
6.Set Attribute
7.Set an Attribute in an Element
8.Copy the attribues on one element to the other
9.Get Attribute
10.Get Attribute by QName
11.Get an Attribute from an Element. Returns an empty String if none found
12.remove Attribute
13.Find Container With Attribute Value Or Create
14.Find Container With Attribute Value Or Create And Set
15.Find the first direct child with a given attribute.
16.Recursive method to find a given attribute value
17.Retutns the value of the named attribute of the given element.
18.An Attributes implementation that can perform more operations than the attribute list helper supplied with the standard SAX2 distribution.