AttributeList
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
|
This interface is deprecated.
This interface has been replaced by the SAX2
Attributes
interface, which includes Namespace support.
Interface for an element's attribute specifications.
This module, both source code and documentation, is in the
Public Domain, and comes with NO WARRANTY.
See http://www.saxproject.org
for further information.
This is the original SAX1 interface for reporting an element's
attributes. Unlike the new Attributes
interface, it does not support Namespace-related information.
When an attribute list is supplied as part of a
startElement
event, the list will return valid results only during the
scope of the event; once the event handler returns control
to the parser, the attribute list is invalid. To save a
persistent copy of the attribute list, use the SAX1
AttributeListImpl
helper class.
An attribute list 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");
[...]
}
Public Method Summary
abstract
int
|
getLength()
Return the number of attributes in this list.
|
abstract
String
|
getName(int i)
Return the name of an attribute in this list (by position).
|
abstract
String
|
getType( String name)
Return the type of an attribute in the list (by name).
|
abstract
String
|
getType(int i)
Return the type of an attribute in the list (by position).
|
abstract
String
|
getValue( String name)
Return the value of an attribute in the list (by name).
|
abstract
String
|
getValue(int i)
Return the value of an attribute in the list (by position).
|
Public Methods
public
abstract
int
getLength
()
Return the number of attributes in this list.
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.
Returns
- The number of attributes in the list.
public
abstract
String
getName
(int i)
Return the name of an attribute in this list (by position).
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.
Parameters
i |
The index of the attribute in the list (starting at 0). |
Returns
- The name of the indexed attribute, or null
if the index is out of range.
public
abstract
String
getType
(String name)
Return the type of an attribute in the list (by 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.
Parameters
name |
The name of the attribute. |
Returns
- The attribute type as a string, or null if no
such attribute exists.
public
abstract
String
getType
(int i)
Return the type of an attribute in the list (by position).
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".
Parameters
i |
The index of the attribute in the list (starting at 0). |
Returns
- The attribute type as a string, or
null if the index is out of range.
public
abstract
String
getValue
(String name)
Return the value of an attribute in the list (by 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.
Parameters
name |
the name of the attribute to return |
Returns
- The attribute value as a string, or null if
no such attribute exists.
public
abstract
String
getValue
(int i)
Return the value of an attribute in the list (by position).
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.
Parameters
i |
The index of the attribute in the list (starting at 0). |
Returns
- The attribute value as a string, or
null if the index is out of range.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eAttributeList\u003c/code\u003e is a deprecated interface, replaced by the \u003ccode\u003eAttributes\u003c/code\u003e interface in SAX2, which provides Namespace support.\u003c/p\u003e\n"],["\u003cp\u003eIt defines methods to retrieve information about an element's attributes, such as the name, type, and value.\u003c/p\u003e\n"],["\u003cp\u003eAttribute values can be accessed by their index or name, but the list is only valid during the \u003ccode\u003estartElement\u003c/code\u003e event.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAttributeListImpl\u003c/code\u003e helper class can be used to save a persistent copy of the attributes.\u003c/p\u003e\n"],["\u003cp\u003eWhile \u003ccode\u003eAttributeList\u003c/code\u003e does not support Namespaces, it provides basic functionality for handling element attributes in SAX1.\u003c/p\u003e\n"]]],[],null,["public interface **AttributeList** \n\n|---|---|---|\n| Known Indirect Subclasses [AttributeListImpl](../../../../reference/org/xml/sax/helpers/AttributeListImpl.html) |---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [AttributeListImpl](../../../../reference/org/xml/sax/helpers/AttributeListImpl.html) | *This class is deprecated. This class implements a deprecated interface, [AttributeList](../../../../reference/org/xml/sax/AttributeList.html); that interface has been replaced by [Attributes](../../../../reference/org/xml/sax/Attributes.html), which is implemented in the [AttributesImpl](../../../../reference/org/xml/sax/helpers/AttributesImpl.html) helper class.* | |||\n\n\n**This interface is deprecated.** \nThis interface has been replaced by the SAX2\n[Attributes](../../../../reference/org/xml/sax/Attributes.html)\ninterface, which includes Namespace support.\n\nInterface for an element's attribute specifications.\n\n\u003e *This module, both source code and documentation, is in the\n\u003e Public Domain, and comes with **NO WARRANTY**.* See \u003chttp://www.saxproject.org\u003e for further information.\n\nThis is the original SAX1 interface for reporting an element's\nattributes. Unlike the new [Attributes](../../../../reference/org/xml/sax/Attributes.html)\ninterface, it does not support Namespace-related information.\n\nWhen an attribute list is supplied as part of a\n[startElement](../../../../reference/org/xml/sax/DocumentHandler.html#startElement(java.lang.String,%20org.xml.sax.AttributeList))\nevent, the list will return valid results only during the\nscope of the event; once the event handler returns control\nto the parser, the attribute list is invalid. To save a\npersistent copy of the attribute list, use the SAX1\n[AttributeListImpl](../../../../reference/org/xml/sax/helpers/AttributeListImpl.html)\nhelper class.\n\nAn attribute list includes only attributes that have been\nspecified or defaulted: #IMPLIED attributes will not be included.\n\nThere are two ways for the SAX application to obtain information\nfrom the AttributeList. First, it can iterate through the entire\nlist: \n\n```\n public void startElement (String name, AttributeList atts) {\n for (int i = 0; i \u003c atts.getLength(); i++) {\n String name = atts.getName(i);\n String type = atts.getType(i);\n String value = atts.getValue(i);\n [...]\n }\n }\n \n```\n\n(Note that the result of getLength() will be zero if there\nare no attributes.)\n\nAs an alternative, the application can request the value or\ntype of specific attributes: \n\n```\n public void startElement (String name, AttributeList atts) {\n String identifier = atts.getValue(\"id\");\n String label = atts.getValue(\"label\");\n [...]\n }\n \n```\n\n\u003cbr /\u003e\n\nSee Also\n\n- [startElement](../../../../reference/org/xml/sax/DocumentHandler.html#startElement(java.lang.String,%20org.xml.sax.AttributeList))\n- [AttributeListImpl](../../../../reference/org/xml/sax/helpers/AttributeListImpl.html) \n\nPublic Method Summary\n\n|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract int | [getLength](../../../../reference/org/xml/sax/AttributeList.html#getLength())() Return the number of attributes in this list. |\n| abstract [String](../../../../reference/java/lang/String.html) | [getName](../../../../reference/org/xml/sax/AttributeList.html#getName(int))(int i) Return the name of an attribute in this list (by position). |\n| abstract [String](../../../../reference/java/lang/String.html) | [getType](../../../../reference/org/xml/sax/AttributeList.html#getType(java.lang.String))([String](../../../../reference/java/lang/String.html) name) Return the type of an attribute in the list (by name). |\n| abstract [String](../../../../reference/java/lang/String.html) | [getType](../../../../reference/org/xml/sax/AttributeList.html#getType(int))(int i) Return the type of an attribute in the list (by position). |\n| abstract [String](../../../../reference/java/lang/String.html) | [getValue](../../../../reference/org/xml/sax/AttributeList.html#getValue(java.lang.String))([String](../../../../reference/java/lang/String.html) name) Return the value of an attribute in the list (by name). |\n| abstract [String](../../../../reference/java/lang/String.html) | [getValue](../../../../reference/org/xml/sax/AttributeList.html#getValue(int))(int i) Return the value of an attribute in the list (by position). |\n\nPublic Methods \n\npublic abstract int\n**getLength**\n() \nReturn the number of attributes in this list.\n\nThe SAX parser may provide attributes in any\narbitrary order, regardless of the order in which they were\ndeclared or specified. The number of attributes may be\nzero.\n\n\u003cbr /\u003e\n\nReturns\n\n- The number of attributes in the list. \n\npublic abstract [String](../../../../reference/java/lang/String.html)\n**getName**\n(int i) \nReturn the name of an attribute in this list (by position).\n\nThe names must be unique: the SAX parser shall not include the\nsame attribute twice. Attributes without values (those declared\n#IMPLIED without a value specified in the start tag) will be\nomitted from the list.\n\nIf the attribute name has a namespace prefix, the prefix\nwill still be attached.\n\n\u003cbr /\u003e\n\nParameters\n\n| i | The index of the attribute in the list (starting at 0). |\n|---|---------------------------------------------------------|\n\nReturns\n\n- The name of the indexed attribute, or null if the index is out of range. \n\nSee Also\n\n- [getLength()](../../../../reference/org/xml/sax/AttributeList.html#getLength()) \n\npublic abstract [String](../../../../reference/java/lang/String.html)\n**getType**\n([String](../../../../reference/java/lang/String.html) name) \nReturn the type of an attribute in the list (by name).\n\nThe return value is the same as the return value for\ngetType(int).\n\nIf the attribute name has a namespace prefix in the document,\nthe application must include the prefix here.\n\n\u003cbr /\u003e\n\nParameters\n\n| name | The name of the attribute. |\n|------|----------------------------|\n\nReturns\n\n- The attribute type as a string, or null if no such attribute exists. \n\nSee Also\n\n- [getType(int)](../../../../reference/org/xml/sax/AttributeList.html#getType(int)) \n\npublic abstract [String](../../../../reference/java/lang/String.html)\n**getType**\n(int i) \nReturn the type of an attribute in the list (by position).\n\nThe attribute type is one of the strings \"CDATA\", \"ID\",\n\"IDREF\", \"IDREFS\", \"NMTOKEN\", \"NMTOKENS\", \"ENTITY\", \"ENTITIES\",\nor \"NOTATION\" (always in upper case).\n\nIf the parser has not read a declaration for the attribute,\nor if the parser does not report attribute types, then it must\nreturn the value \"CDATA\" as stated in the XML 1.0 Recommentation\n(clause 3.3.3, \"Attribute-Value Normalization\").\n\nFor an enumerated attribute that is not a notation, the\nparser will report the type as \"NMTOKEN\".\n\n\u003cbr /\u003e\n\nParameters\n\n| i | The index of the attribute in the list (starting at 0). |\n|---|---------------------------------------------------------|\n\nReturns\n\n- The attribute type as a string, or null if the index is out of range. \n\nSee Also\n\n- [getLength()](../../../../reference/org/xml/sax/AttributeList.html#getLength())\n- [getType(java.lang.String)](../../../../reference/org/xml/sax/AttributeList.html#getType(java.lang.String)) \n\npublic abstract [String](../../../../reference/java/lang/String.html)\n**getValue**\n([String](../../../../reference/java/lang/String.html) name) \nReturn the value of an attribute in the list (by name).\n\nThe return value is the same as the return value for\ngetValue(int).\n\nIf the attribute name has a namespace prefix in the document,\nthe application must include the prefix here.\n\n\u003cbr /\u003e\n\nParameters\n\n| name | the name of the attribute to return |\n|------|-------------------------------------|\n\nReturns\n\n- The attribute value as a string, or null if no such attribute exists. \n\nSee Also\n\n- [getValue(int)](../../../../reference/org/xml/sax/AttributeList.html#getValue(int)) \n\npublic abstract [String](../../../../reference/java/lang/String.html)\n**getValue**\n(int i) \nReturn the value of an attribute in the list (by position).\n\nIf the attribute value is a list of tokens (IDREFS,\nENTITIES, or NMTOKENS), the tokens will be concatenated\ninto a single string separated by whitespace.\n\n\u003cbr /\u003e\n\nParameters\n\n| i | The index of the attribute in the list (starting at 0). |\n|---|---------------------------------------------------------|\n\nReturns\n\n- The attribute value as a string, or null if the index is out of range. \n\nSee Also\n\n- [getLength()](../../../../reference/org/xml/sax/AttributeList.html#getLength())\n- [getValue(java.lang.String)](../../../../reference/org/xml/sax/AttributeList.html#getValue(java.lang.String))"]]