Retutns the value of the named attribute of the given element. : DOM Attribute « XML « Java






Retutns the value of the named attribute of the given element.

  
import org.w3c.dom.Attr;
import org.w3c.dom.Element;

public class Utils {


  /**
   * <p>Retutns the value of the named attribute of the given
   * element. If there is no such attribute, returns null.</p>
   *
   * @param element element
   * @param name name
   * @return value
   */
  public static String getAttributeValue(Element element, String name)
  {
      Attr attribute = element.getAttributeNode(name);
      if(attribute == null) {
          return null;
      }
      else {
          return attribute.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.Returns null, not "", for a nonexistent attribute
18.An Attributes implementation that can perform more operations than the attribute list helper supplied with the standard SAX2 distribution.