This interface represents a list of attributes of an XML element and includes information about the attribute names, types, and values. If the SAX parser has read a DTD or schema for the document, this list of attributes will include attributes that are not explicitly specified in the document but which have a default value specified in the DTD or schema.
The most commonly used method is
getValue( ) which
returns the value of a named attribute (there is also a version of
this method that returns the value of a numbered attribute; it is
discussed later). If the SAX parser is not processing namespaces, you
can use the one-argument version of
Otherwise, use the two argument version to specify the URI that
uniquely identifies the namespace, and the “local
name” of the desired attribute within that namespace
getType( ) methods are similar, except that
they return the type of the named attribute, rather than its value.
getType( ) can only return useful
information if the parser has read a DTD or schema for the document
and knows the type of each attribute.
In XML documents the attributes of a tag can appear in any order.
Attributes objects make no attempt to preserve the
document source order of the tags. Nevertheless, it does impose an
ordering on the attributes so that you can loop through them.
getLength( ) returns the number of elements in the
list. There are versions of
getValue( ) and
getType( ) that return the value and type of ...
Get Java in a Nutshell, 5th Edition 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.