- java.lang.Object
-
- org.xml.sax.helpers.AttributesImpl
-
- All Implemented Interfaces:
-
Attributes
- 已知直接子类:
-
Attributes2Impl
public class AttributesImpl extends Object implements 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接口的默认实现,添加了操纵器,以便可以修改或重用列表。这个类有两个典型的用法:
- 在
startElement事件中获取属性对象的持久快照; 要么 - 在SAX2驱动程序或过滤器中构造或修改Attributes对象。
这个类代替了现在不推荐的SAX1
AttributeListImpl类; 除了支持更新的Attributes界面,而不是不赞成使用的AttributeList接口,它还包括使用单个数组而不是一组向量更有效的实现。- 从以下版本开始:
- 1.4,SAX 2.0
-
-
构造方法摘要
构造方法 Constructor 描述 AttributesImpl()构造一个新的空的AttributesImpl对象。AttributesImpl(Attributes atts)复制现有的Attributes对象。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidaddAttribute(String uri, String localName, String qName, String type, String value)将属性添加到列表的末尾。voidclear()清除属性列表以供重用。intgetIndex(String qName)通过合格(前缀)名称查找属性的索引。intgetIndex(String uri, String localName)通过命名空间名称查找属性的索引。intgetLength()返回列表中的属性数。StringgetLocalName(int index)返回属性的本地名称。StringgetQName(int index)返回属性的合格(前缀)名称。StringgetType(int index)通过索引返回属性的类型。StringgetType(String qName)通过合格(前缀)名称查找属性的类型。StringgetType(String uri, String localName)通过Namespace限定名称查找属性的类型。StringgetURI(int index)返回属性的命名空间URI。StringgetValue(int index)通过索引返回属性的值。StringgetValue(String qName)通过合格(前缀)名称查找属性的值。StringgetValue(String uri, String localName)通过Namespace限定名查找属性的值。voidremoveAttribute(int index)从列表中删除一个属性。voidsetAttribute(int index, String uri, String localName, String qName, String type, String value)在列表中设置一个属性。voidsetAttributes(Attributes atts)复制整个Attributes对象。voidsetLocalName(int index, String localName)设置特定属性的本地名称。voidsetQName(int index, String qName)设置特定属性的限定名称。voidsetType(int index, String type)设置特定属性的类型。voidsetURI(int index, String uri)设置特定属性的命名空间URI。voidsetValue(int index, String value)设置特定属性的值。
-
-
-
构造方法详细信息
-
AttributesImpl
public AttributesImpl()
构造一个新的空的AttributesImpl对象。
-
AttributesImpl
public AttributesImpl(Attributes atts)
复制现有的Attributes对象。这个构造函数在
startElement事件中特别有用。- 参数
-
atts- 现有的属性对象。
-
-
方法详细信息
-
getLength
public int getLength()
返回列表中的属性数。- Specified by:
-
getLength在接口Attributes - 结果
- 列表中的属性数。
- 另请参见:
-
Attributes.getLength()
-
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- 属性的索引(从零开始)。 - 结果
- 属性的限定名称,空字符串(如果没有可用),如果索引超出范围则为空。
- 另请参见:
-
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- 属性的Namespace URI,如果没有可用,则为空字符串。 -
localName- 属性的本地名称。 - 结果
- 属性的索引,如果没有匹配则为-1。
- 另请参见:
-
Attributes.getIndex(java.lang.String,java.lang.String)
-
getIndex
public int getIndex(String qName)
通过合格(前缀)名称查找属性的索引。- Specified by:
-
getIndex在接口Attributes - 参数
-
qName- 限定名称。 - 结果
- 属性的索引,如果没有匹配则为-1。
- 另请参见:
-
Attributes.getIndex(java.lang.String)
-
getType
public String getType(String uri, String localName)
通过Namespace限定名称查找属性的类型。- Specified by:
-
getType在接口Attributes - 参数
-
uri- 命名空间URI,或没有明确命名空间URI的名称的空字符串。 -
localName- 本地名称。 - 结果
- 属性的类型,如果没有匹配的属性,则为null。
- 另请参见:
-
Attributes.getType(java.lang.String,java.lang.String)
-
getType
public String getType(String qName)
通过合格(前缀)名称查找属性的类型。- Specified by:
-
getType在接口Attributes - 参数
-
qName- 限定名称。 - 结果
- 属性的类型,如果没有匹配的属性,则为null。
- 另请参见:
-
Attributes.getType(java.lang.String)
-
getValue
public String getValue(String uri, String localName)
通过Namespace限定名查找属性的值。- Specified by:
-
getValue在接口Attributes - 参数
-
uri- 名称空间URI,或没有显式命名空间URI的名称的空字符串。 -
localName- 本地名称。 - 结果
- 属性的值,如果没有匹配的属性,则为null。
- 另请参见:
-
Attributes.getValue(java.lang.String,java.lang.String)
-
getValue
public String getValue(String qName)
通过合格(前缀)名称查找属性的值。- Specified by:
-
getValue在接口Attributes - 参数
-
qName- 限定名称。 - 结果
- 属性的值,如果没有匹配的属性,则为null。
- 另请参见:
-
Attributes.getValue(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- 属性的Namespace 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.
-
-