The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > org.w3c.dom  [30 examples] > Element Attributes  [5 examples]

e538. Determining If an Attribute Was Supplied in a DOM Element

In the case of an attribute with a default value, it is possible to determine if the attribute was explicitly supplied in the original XML document or automatically created when it was parsed.

Note: If the attribute value is changed in the DOM document, the attributed is considered to have been supplied, even if the new value is the same as the default value.

    // Get Attr node
    Attr attr = (Attr)element.getAttributeNode("attrName");
    boolean wasSpecified = attr != null && attr.getSpecified();

 Related Examples
e534. Getting and Setting an Attribute in a DOM Element
e535. Adding and Removing an Attribute in a DOM Element
e536. Listing All the Attributes of a DOM Element
e537. Removing All the Attributes in a DOM Element

See also: Adding and Removing Nodes    Elements    Getting Nodes    Text Nodes    XPath   


© 2002 Addison-Wesley.