模块  java.xml
软件包  org.xml.sax.helpers

Class AttributesImpl

  • 实现的所有接口
    Attributes
    已知直接子类:
    Attributes2Impl

    public class AttributesImpl
    extends Object
    implements Attributes
    Attributes接口的默认实现。
    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.

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

    这个类有两种典型用法:

    1. startElement事件中获取 Attributes对象的持久快照; 要么
    2. 在SAX2驱动程序或过滤器中构造或修改Attributes对象。

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

    从以下版本开始:
    1.4,SAX 2.0
    • 构造方法详细信息

      • AttributesImpl

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

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

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

        参数
        atts - 现有的Attributes对象。
    • 方法详细信息

      • getURI

        public String getURI​(int index)
        返回属性的名称空间URI。
        Specified by:
        getURI接口 Attributes
        参数
        index - 属性的索引(从零开始)。
        结果
        名称空间URI,如果没有可用空字符串,如果索引超出范围则为null。
        另请参见:
        Attributes.getURI(int)
      • getLocalName

        public String getLocalName​(int index)
        返回属性的本地名称。
        Specified by:
        getLocalName接口 Attributes
        参数
        index - 属性的索引(从零开始)。
        结果
        属性的本地名称,如果没有,则为空字符串;如果索引超出范围,则为null。
        另请参见:
        Attributes.getLocalName(int)
      • getQName

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

        public String getType​(int index)
        按索引返回属性的类型。
        Specified by:
        getType接口 Attributes
        参数
        index - 属性的索引(从零开始)。
        结果
        属性的类型,如果类型未知,则为“CDATA”;如果索引超出范围,则为null。
        另请参见:
        Attributes.getType(int)
      • getValue

        public String getValue​(int index)
        按索引返回属性的值。
        Specified by:
        getValue接口 Attributes
        参数
        index - 属性的索引(从零开始)。
        结果
        属性的值,如果索引超出范围,则返回null。
        另请参见:
        Attributes.getValue(int)
      • getIndex

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

        在许多情况下,查找名称一次并使用索引查询方法而不是重复使用名称查询方法会更有效。

        Specified by:
        getIndex接口 Attributes
        参数
        uri - 属性的名称空间URI,如果没有,则为空字符串。
        localName - 属性的本地名称。
        结果
        属性的索引,如果没有匹配,则返回-1。
        另请参见:
        Attributes.getIndex(java.lang.String,java.lang.String)
      • 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 - When the supplied index does not point to an attribute in the list.