The Attr Interface

Probably 90 percent of the time, everything you need to do with attributes can be done purely through the various attribute methods of the Element interface. However, occasionally the Attr interface comes in handy. An Attr object represents an attribute, whether explicitly included in the document or present by default from the schema.

Example 11.15 summarizes the Attr interface. In addition to methods inherited from the Node superinterface, Attr includes methods to do the following:

  • Get the full name of the attribute (including a prefix, if any)

  • Determine whether the attribute was specified in the document or merely appears by default from the DTD or schema

  • Get the element that contains this attribute

  • Get the value of the attribute. ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.