1. // SAX Attribute List Interface.
  2. // No warranty; no copyright -- use this as you will.
  3. // $Id: AttributeList.java,v 1.1 2001/05/20 03:12:56 curcuru Exp $
  4. package org.xml.sax;
  5. /**
  6. * Interface for an element's attribute specifications.
  7. *
  8. * <blockquote>
  9. * <em>This module, both source code and documentation, is in the
  10. * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
  11. * </blockquote>
  12. *
  13. * <p>This is the original SAX1 interface for reporting an element's
  14. * attributes. Unlike the new {@link org.xml.sax.Attributes Attributes}
  15. * interface, it does not support Namespace-related information.</p>
  16. *
  17. * <p>When an attribute list is supplied as part of a
  18. * {@link org.xml.sax.DocumentHandler#startElement startElement}
  19. * event, the list will return valid results only during the
  20. * scope of the event; once the event handler returns control
  21. * to the parser, the attribute list is invalid. To save a
  22. * persistent copy of the attribute list, use the SAX1
  23. * {@link org.xml.sax.helpers.AttributeListImpl AttributeListImpl}
  24. * helper class.</p>
  25. *
  26. * <p>An attribute list includes only attributes that have been
  27. * specified or defaulted: #IMPLIED attributes will not be included.</p>
  28. *
  29. * <p>There are two ways for the SAX application to obtain information
  30. * from the AttributeList. First, it can iterate through the entire
  31. * list:</p>
  32. *
  33. * <pre>
  34. * public void startElement (String name, AttributeList atts) {
  35. * for (int i = 0; i < atts.getLength(); i++) {
  36. * String name = atts.getName(i);
  37. * String type = atts.getType(i);
  38. * String value = atts.getValue(i);
  39. * [...]
  40. * }
  41. * }
  42. * </pre>
  43. *
  44. * <p>(Note that the result of getLength() will be zero if there
  45. * are no attributes.)
  46. *
  47. * <p>As an alternative, the application can request the value or
  48. * type of specific attributes:</p>
  49. *
  50. * <pre>
  51. * public void startElement (String name, AttributeList atts) {
  52. * String identifier = atts.getValue("id");
  53. * String label = atts.getValue("label");
  54. * [...]
  55. * }
  56. * </pre>
  57. *
  58. * @deprecated This interface has been replaced by the SAX2
  59. * {@link org.xml.sax.Attributes Attributes}
  60. * interface, which includes Namespace support.
  61. * @since SAX 1.0
  62. * @author David Megginson,
  63. * <a href="mailto:sax@megginson.com">sax@megginson.com</a>
  64. * @version 2.0r2pre
  65. * @see org.xml.sax.DocumentHandler#startElement startElement
  66. * @see org.xml.sax.helpers.AttributeListImpl AttributeListImpl
  67. */
  68. public interface AttributeList {
  69. ////////////////////////////////////////////////////////////////////
  70. // Iteration methods.
  71. ////////////////////////////////////////////////////////////////////
  72. /**
  73. * Return the number of attributes in this list.
  74. *
  75. * <p>The SAX parser may provide attributes in any
  76. * arbitrary order, regardless of the order in which they were
  77. * declared or specified. The number of attributes may be
  78. * zero.</p>
  79. *
  80. * @return The number of attributes in the list.
  81. */
  82. public abstract int getLength ();
  83. /**
  84. * Return the name of an attribute in this list (by position).
  85. *
  86. * <p>The names must be unique: the SAX parser shall not include the
  87. * same attribute twice. Attributes without values (those declared
  88. * #IMPLIED without a value specified in the start tag) will be
  89. * omitted from the list.</p>
  90. *
  91. * <p>If the attribute name has a namespace prefix, the prefix
  92. * will still be attached.</p>
  93. *
  94. * @param i The index of the attribute in the list (starting at 0).
  95. * @return The name of the indexed attribute, or null
  96. * if the index is out of range.
  97. * @see #getLength
  98. */
  99. public abstract String getName (int i);
  100. /**
  101. * Return the type of an attribute in the list (by position).
  102. *
  103. * <p>The attribute type is one of the strings "CDATA", "ID",
  104. * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES",
  105. * or "NOTATION" (always in upper case).</p>
  106. *
  107. * <p>If the parser has not read a declaration for the attribute,
  108. * or if the parser does not report attribute types, then it must
  109. * return the value "CDATA" as stated in the XML 1.0 Recommentation
  110. * (clause 3.3.3, "Attribute-Value Normalization").</p>
  111. *
  112. * <p>For an enumerated attribute that is not a notation, the
  113. * parser will report the type as "NMTOKEN".</p>
  114. *
  115. * @param i The index of the attribute in the list (starting at 0).
  116. * @return The attribute type as a string, or
  117. * null if the index is out of range.
  118. * @see #getLength
  119. * @see #getType(java.lang.String)
  120. */
  121. public abstract String getType (int i);
  122. /**
  123. * Return the value of an attribute in the list (by position).
  124. *
  125. * <p>If the attribute value is a list of tokens (IDREFS,
  126. * ENTITIES, or NMTOKENS), the tokens will be concatenated
  127. * into a single string separated by whitespace.</p>
  128. *
  129. * @param i The index of the attribute in the list (starting at 0).
  130. * @return The attribute value as a string, or
  131. * null if the index is out of range.
  132. * @see #getLength
  133. * @see #getValue(java.lang.String)
  134. */
  135. public abstract String getValue (int i);
  136. ////////////////////////////////////////////////////////////////////
  137. // Lookup methods.
  138. ////////////////////////////////////////////////////////////////////
  139. /**
  140. * Return the type of an attribute in the list (by name).
  141. *
  142. * <p>The return value is the same as the return value for
  143. * getType(int).</p>
  144. *
  145. * <p>If the attribute name has a namespace prefix in the document,
  146. * the application must include the prefix here.</p>
  147. *
  148. * @param name The name of the attribute.
  149. * @return The attribute type as a string, or null if no
  150. * such attribute exists.
  151. * @see #getType(int)
  152. */
  153. public abstract String getType (String name);
  154. /**
  155. * Return the value of an attribute in the list (by name).
  156. *
  157. * <p>The return value is the same as the return value for
  158. * getValue(int).</p>
  159. *
  160. * <p>If the attribute name has a namespace prefix in the document,
  161. * the application must include the prefix here.</p>
  162. *
  163. * @param i The index of the attribute in the list.
  164. * @return The attribute value as a string, or null if
  165. * no such attribute exists.
  166. * @see #getValue(int)
  167. */
  168. public abstract String getValue (String name);
  169. }
  170. // end of AttributeList.java