模块 java.xml

类 AttributesImpl

java.lang.Object
org.xml.sax.helpers.AttributesImpl
所有已实现的接口:
Attributes
已知子类:
Attributes2Impl

public class AttributesImpl extends Object implements Attributes
属性接口的默认实现。

此类提供 SAX2 Attributes 接口的默认实现,并添加了操纵器以便可以修改或重用列表。

这个类有两个典型的用途:

  1. startElement 事件中拍摄属性对象的持久快照;或者
  2. 在 SAX2 驱动程序或过滤器中构造或修改属性对象。

该类取代了现已弃用的 SAX1 AttributeListImpl 类;除了支持更新的 Attributes 接口而不是已弃用的 AttributeList 接口外,它还包括使用单个数组而不是一组 Vectors 的更有效的实现。

自从:
1.4, SAX 2.0
  • 构造方法详细信息

    • AttributesImpl

      public AttributesImpl()
      构造一个新的空 AttributesImpl 对象。
    • AttributesImpl

      public AttributesImpl(Attributes  atts)
      复制现有的 Attributes 对象。

      此构造函数在 startElement 事件中特别有用。

      参数:
      atts - 现有的属性对象。
  • 方法详情

    • getLength

      public int getLength()
      返回列表中的属性数。
      指定者:
      getLength 在接口 Attributes
      返回:
      列表中的属性数。
      参见:
    • getURI

      public String  getURI(int index)
      返回属性的命名空间 URI。
      指定者:
      getURI 在接口 Attributes
      参数:
      index - 属性的索引(从零开始)。
      返回:
      命名空间 URI,如果没有可用则为空字符串,如果索引超出范围则为 null。
      参见:
    • getLocalName

      public String  getLocalName(int index)
      返回属性的本地名称。
      指定者:
      getLocalName 在接口 Attributes
      参数:
      index - 属性的索引(从零开始)。
      返回:
      属性的本地名称,如果没有可用的则为空字符串,如果索引超出范围则为 null。
      参见:
    • getQName

      public String  getQName(int index)
      返回属性的限定(前缀)名称。
      指定者:
      getQName 在接口 Attributes
      参数:
      index - 属性的索引(从零开始)。
      返回:
      属性的限定名称,如果没有可用的则为空字符串,如果索引超出范围则为 null。
      参见:
    • getType

      public String  getType(int index)
      按索引返回属性的类型。
      指定者:
      getType 在接口 Attributes
      参数:
      index - 属性的索引(从零开始)。
      返回:
      属性的类型,如果类型未知则为“CDATA”,如果索引超出范围则为 null。
      参见:
    • getValue

      public String  getValue(int index)
      按索引返回属性值。
      指定者:
      getValue 在接口 Attributes
      参数:
      index - 属性的索引(从零开始)。
      返回:
      属性的值,如果索引超出范围则为 null。
      参见:
    • getIndex

      public int getIndex(String  uri, String  localName)
      按命名空间名称查找属性的索引。

      在很多情况下,查找一次名称并使用索引查询方法比重复使用名称查询方法效率更高。

      指定者:
      getIndex 在接口 Attributes
      参数:
      uri - 属性的命名空间 URI,如果没有可用的,则为空字符串。
      localName - 属性的本地名称。
      返回:
      属性的索引,如果没有匹配项,则为 -1。
      参见:
    • getIndex

      public int getIndex(String  qName)
      通过限定(前缀)名称查找属性的索引。
      指定者:
      getIndex 在接口 Attributes
      参数:
      qName - 限定名称。
      返回:
      属性的索引,如果没有匹配项,则为 -1。
      参见:
    • getType

      public String  getType(String  uri, String  localName)
      通过名称空间限定的名称查找属性的类型。
      指定者:
      getType 在接口 Attributes
      参数:
      uri - 命名空间 URI,或没有显式命名空间 URI 的名称的空字符串。
      localName - 本地名称。
      返回:
      属性的类型,如果没有匹配的属性,则为 null。
      参见:
    • getType

      public String  getType(String  qName)
      通过限定(前缀)名称查找属性的类型。
      指定者:
      getType 在接口 Attributes
      参数:
      qName - 限定名称。
      返回:
      属性的类型,如果没有匹配的属性,则为 null。
      参见:
    • getValue

      public String  getValue(String  uri, String  localName)
      通过名称空间限定的名称查找属性的值。
      指定者:
      getValue 在接口 Attributes
      参数:
      uri - 命名空间 URI,或没有显式命名空间 URI 的名称的空字符串。
      localName - 本地名称。
      返回:
      属性的值,如果没有匹配的属性,则为 null。
      参见:
    • getValue

      public String  getValue(String  qName)
      通过限定(前缀)名称查找属性值。
      指定者:
      getValue 在接口 Attributes
      参数:
      qName - 限定名称。
      返回:
      属性的值,如果没有匹配的属性,则为 null。
      参见:
    • clear

      public void clear()
      清除属性列表以便重新使用。

      请注意,此调用释放的内存很少:保留当前数组以便可以重复使用。

    • setAttributes

      public void setAttributes(Attributes  atts)
      复制整个 Attributes 对象。

      重用现有对象可能比不断分配新对象更有效。

      参数:
      atts - 要复制的属性。
    • addAttribute

      public void addAttribute(String  uri, String  localName, String  qName, String  type, String  value)
      将属性添加到列表的末尾。

      为了速度,此方法不检查属性是否已在列表中:这是应用程序的责任。

      参数:
      uri - 命名空间 URI,如果没有可用的或未执行命名空间处理,则为空字符串。
      localName - 本地名称,如果未执行命名空间处理,则为空字符串。
      qName - 限定(前缀)名称,如果限定名称不可用,则为空字符串。
      type - 作为字符串的属性类型。
      value - 属性值。
    • setAttribute

      public void setAttribute(int index, String  uri, String  localName, String  qName, String  type, String  value)
      在列表中设置一个属性。

      为了速度,此方法不检查名称冲突或格式是否正确:此类检查由应用程序负责。

      参数:
      index - 属性的索引(从零开始)。
      uri - 命名空间 URI,如果没有可用的或未执行命名空间处理,则为空字符串。
      localName - 本地名称,如果未执行命名空间处理,则为空字符串。
      qName - 限定名称,如果限定名称不可用,则为空字符串。
      type - 作为字符串的属性类型。
      value - 属性值。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • removeAttribute

      public void removeAttribute(int index)
      从列表中删除一个属性。
      参数:
      index - 属性的索引(从零开始)。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • setURI

      public void setURI(int index, String  uri)
      设置特定属性的命名空间 URI。
      参数:
      index - 属性的索引(从零开始)。
      uri - 属性的命名空间 URI,或空字符串表示无。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • setLocalName

      public void setLocalName(int index, String  localName)
      设置特定属性的本地名称。
      参数:
      index - 属性的索引(从零开始)。
      localName - 属性的本地名称,或无的空字符串。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • setQName

      public void setQName(int index, String  qName)
      设置特定属性的限定名称。
      参数:
      index - 属性的索引(从零开始)。
      qName - 属性的限定名称,或无的空字符串。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • setType

      public void setType(int index, String  type)
      设置特定属性的类型。
      参数:
      index - 属性的索引(从零开始)。
      type - 属性的类型。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。
    • setValue

      public void setValue(int index, String  value)
      设置特定属性的值。
      参数:
      index - 属性的索引(从零开始)。
      value - 属性值。
      抛出:
      ArrayIndexOutOfBoundsException - 当提供的索引未指向列表中的属性时。