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 getValue( ).
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
. The getType( ) methods are similar, except that
they return the type of the named attribute, rather than its value.
Note that 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 the
attribute at a specified position in the list. You can also query the
name of the attribute at a specified position, although the way you
do this depends on whether the parser handles namespaces or not. If
it does not process namespaces, use getQName( ) to
get the name at a specified position. Otherwise, use getURI(
) and getLocalName( ) to obtain the URI
and local name pair for the numbered attribute. Note that
getQName( ) may return the empty string when
namespace processing is on, and getLocalName( )
may return the empty string if namespace processing is off.
public interface Attributes {
// Public Instance Methods
int getIndex(String qName);
int getIndex(String uri, String localName);
int getLength( );
String getLocalName(int index);
String getQName(int index);
String getType(String qName);
String getType(int index);
String getType(String uri, String localName);
String getURI(int index);
String getValue(String qName);
String getValue(int index);
String getValue(String uri, String localName);
}
Implementations
org.xml.sax.ext.Attributes2,
org.xml.sax.helpers.AttributesImpl
Passed To
org.xml.sax.ContentHandler.startElement( ),
org.xml.sax.ext.Attributes2Impl.{Attributes2Impl(
), setAttributes( )},
org.xml.sax.helpers.AttributesImpl.{AttributesImpl(
), setAttributes( )},
org.xml.sax.helpers.DefaultHandler.startElement(
), org.xml.sax.helpers.XMLFilterImpl.startElement(
),
org.xml.sax.helpers.XMLReaderAdapter.startElement(
)
|