public interface CharacterData
implements Node
| org.w3c.dom.CharacterData |
| |
CharacterData接口使用一组用于访问DOM中字符数据的属性和方法来扩展Node。 为了清楚起见,这里定义了这个集合,而不是每个使用这些属性和方法的对象。 没有DOM对象直接对应于CharacterData ,尽管Text和其他人继承了它的接口。 这个接口中的所有offsets从0开始。
正如DOMString接口中所解释的,DOM中的文本字符串以UTF-16表示,即以16位单元的序列表示。 在下文中,术语16位单元在必要时用于指示在CharacterData上的索引是以16位为单位完成的。
另见 Document Object Model (DOM) Level 3 Core Specification 。
Inherited constants |
|---|
org.w3c.dom.Node
|
Public methods |
|
|---|---|
abstract void |
appendData(String arg) 将字符串追加到节点的字符数据的末尾。 |
abstract void |
deleteData(int offset, int count) 从节点中删除一系列的16位单元。 |
abstract String |
getData() 实现此接口的节点的字符数据。 |
abstract int |
getLength() 通过 |
abstract void |
insertData(int offset, String arg) 以指定的16位单位偏移量插入一个字符串。 |
abstract void |
replaceData(int offset, int count, String arg) 用指定的字符串替换从指定的16位单位偏移量开始的字符。 |
abstract void |
setData(String data) 实现此接口的节点的字符数据。 |
abstract String |
substringData(int offset, int count) 从节点中提取一系列数据。 |
Inherited methods |
|
|---|---|
org.w3c.dom.Node
|
|
void appendData (String arg)
将字符串追加到节点的字符数据的末尾。 一旦成功, data提供访问指定的data和DOMString的级联。
| Parameters | |
|---|---|
arg |
String: The DOMString to append. |
| Throws | |
|---|---|
DOMException |
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
void deleteData (int offset,
int count)
从节点中删除一系列的16位单元。 一旦成功, data和length反映了这一变化。
| Parameters | |
|---|---|
offset |
int: The offset from which to start removing. |
count |
int: The number of 16-bit units to delete. If the sum of offset and count exceeds length then all 16-bit units from offset to the end of the data are deleted. |
| Throws | |
|---|---|
DOMException |
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units in data, or if the specified count is negative. NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
String getData ()
实现此接口的节点的字符数据。 DOM实现可能不会对可能存储在CharacterData节点中的数据量施加任意限制。 但是,实施限制可能意味着整个节点的数据可能不适合单个DOMString 。 在这种情况下,用户可以拨打substringData来检索大小合适的数据。
| Returns | |
|---|---|
String |
|
| Throws | |
|---|---|
DOMException |
DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in a DOMString variable on the implementation platform. |
int getLength ()
通过data和下面的substringData方法可用的16位单元的数量。 这可能具有零值,即CharacterData节点可能为空。
| Returns | |
|---|---|
int |
|
void insertData (int offset,
String arg)
以指定的16位单位偏移量插入一个字符串。
| Parameters | |
|---|---|
offset |
int: The character offset at which to insert. |
arg |
String: The DOMString to insert. |
| Throws | |
|---|---|
DOMException |
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units in data. NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
void replaceData (int offset,
int count,
String arg)
用指定的字符串替换从指定的16位单位偏移量开始的字符。
| Parameters | |
|---|---|
offset |
int: The offset from which to start replacing. |
count |
int: The number of 16-bit units to replace. If the sum of offset and count exceeds length, then all 16-bit units to the end of the data are replaced; (i.e., the effect is the same as a remove method call with the same range, followed by an append method invocation). |
arg |
String: The DOMString with which the range must be replaced. |
| Throws | |
|---|---|
DOMException |
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units in data, or if the specified count is negative. NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. |
void setData (String data)
实现此接口的节点的字符数据。 DOM实现可能不会对可能存储在CharacterData节点中的数据量施加任意限制。 但是,实施限制可能意味着整个节点的数据可能不适合单个DOMString 。 在这种情况下,用户可以拨打substringData来检索大小合适的数据。
| Parameters | |
|---|---|
data |
String
|
| Throws | |
|---|---|
DOMException |
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. |
String substringData (int offset, int count)
从节点中提取一系列数据。
| Parameters | |
|---|---|
offset |
int: Start offset of substring to extract. |
count |
int: The number of 16-bit units to extract. |
| Returns | |
|---|---|
String |
The specified substring. If the sum of offset and count exceeds the length, then all 16-bit units to the end of the data are returned. |
| Throws | |
|---|---|
DOMException |
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of 16-bit units in data, or if the specified count is negative. DOMSTRING_SIZE_ERR: Raised if the specified range of text does not fit into a DOMString. |