Contents | Package | Class | Tree | Deprecated | Index | Help | XML for Java 1.0.4 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
The SAX parser implements this interface and passes an instance to the SAX application as the second argument of each startElement event.
The instance provided will return valid results only during the scope of the startElement invocation (to save it for future use, the application must make a copy: the AttributeListImpl helper class provides a convenient constructor for doing so).
An AttributeList includes only attributes that have been specified or defaulted: #IMPLIED attributes will not be included.
There are two ways for the SAX application to obtain information from the AttributeList. First, it can iterate through the entire list:
public void startElement (String name, AttributeList atts) { for (int i = 0; i < atts.getLength(); i++) { String name = atts.getName(i); String type = atts.getType(i); String value = atts.getValue(i); [...] } }
(Note that the result of getLength() will be zero if there are no attributes.)
As an alternative, the application can request the value or type of specific attributes:
public void startElement (String name, AttributeList atts) { String identifier = atts.getValue("id"); String label = atts.getValue("label"); [...] }
The AttributeListImpl helper class provides a convenience implementation for use by parser or application writers.
Method Summary | |
int | getLength()
|
java.lang.String | getName(int i)
|
java.lang.String | getType(int i)
|
java.lang.String | getType(java.lang.String name)
|
java.lang.String | getValue(int i)
|
java.lang.String | getValue(java.lang.String name)
|
Method Detail |
public int getLength()
The SAX parser may provide attributes in any arbitrary order, regardless of the order in which they were declared or specified. The number of attributes may be zero.
public java.lang.String getName(int i)
The names must be unique: the SAX parser shall not include the same attribute twice. Attributes without values (those declared #IMPLIED without a value specified in the start tag) will be omitted from the list.
If the attribute name has a namespace prefix, the prefix will still be attached.
i
- The index of the attribute in the list (starting at 0).
public java.lang.String getType(int i)
The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION" (always in upper case).
If the parser has not read a declaration for the attribute, or if the parser does not report attribute types, then it must return the value "CDATA" as stated in the XML 1.0 Recommentation (clause 3.3.3, "Attribute-Value Normalization").
For an enumerated attribute that is not a notation, the parser will report the type as "NMTOKEN".
i
- The index of the attribute in the list (starting at 0).
public java.lang.String getValue(int i)
If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will be concatenated into a single string separated by whitespace.
i
- The index of the attribute in the list (starting at 0).
public java.lang.String getType(java.lang.String name)
The return value is the same as the return value for getType(int).
If the attribute name has a namespace prefix in the document, the application must include the prefix here.
name
- The name of the attribute.
public java.lang.String getValue(java.lang.String name)
The return value is the same as the return value for getValue(int).
If the attribute name has a namespace prefix in the document, the application must include the prefix here.
i
- The index of the attribute in the list.
Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |