public interface Element extends Node
Element
接口表示一个元素在HTML或XML文档。元素可能具有相关的属性;因为
Element
接口继承
Node
,通用
Node
接口属性
attributes
可以用于检索一个元素的所有属性的设置。在
Element
接口来检索一个
Attr
对象的名称或名称属性值的方法。在XML中,其中一个属性值可以包含实体引用,一个
Attr
对象应检索研究可能相当复杂的亚树表示的属性值。在HTML中,另一方面,所有的属性都有简单的字符串值,方法直接访问一个属性的值可以被用来作为一个方便。
在DOM级别2 注:,方法normalize
是继承了Node
界面,很是感动。
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
Modifier and Type | Method and Description |
---|---|
String |
getAttribute(String name)
通过名称检索属性值。
|
Attr |
getAttributeNode(String name)
通过名称检索属性节点。
|
Attr |
getAttributeNodeNS(String namespaceURI, String localName)
检索一个
Attr 节点的本地名称和命名空间URI。
|
String |
getAttributeNS(String namespaceURI, String localName)
检索属性值的本地名称和命名空间URI。
|
NodeList |
getElementsByTagName(String name)
返回一个
NodeList 所有后裔
Elements 与给定的标签名称,在文档顺序。
|
NodeList |
getElementsByTagNameNS(String namespaceURI, String localName)
按照文档顺序返回一个
NodeList 所有后代
Elements 与给定的本地名称和命名空间URI。
|
TypeInfo |
getSchemaTypeInfo()
与此元素关联的类型信息。
|
String |
getTagName()
元素的名称。
|
boolean |
hasAttribute(String name)
true 时返回具有给定名称的属性指定这个元素或具有默认值,否则
false 。
|
boolean |
hasAttributeNS(String namespaceURI, String localName)
true 时返回与给定的本地名称和命名空间URI属性指定该元素或具有默认值,否则
false 。
|
void |
removeAttribute(String name)
按名称删除属性。
|
Attr |
removeAttributeNode(Attr oldAttr)
移除指定的属性节点。
|
void |
removeAttributeNS(String namespaceURI, String localName)
删除一个属性的本地名称和命名空间URI。
|
void |
setAttribute(String name, String value)
添加一个新属性。
|
Attr |
setAttributeNode(Attr newAttr)
添加一个新的属性节点。
|
Attr |
setAttributeNodeNS(Attr newAttr)
添加一个新属性。
|
void |
setAttributeNS(String namespaceURI, String qualifiedName, String value)
添加一个新属性。
|
void |
setIdAttribute(String name, boolean isId)
如果参数
isId 是
true ,这个方法声明指定的属性是用户自定义的ID属性。
|
void |
setIdAttributeNode(Attr idAttr, boolean isId)
如果参数
isId 是
true ,这个方法声明指定的属性是用户自定义的ID属性。
|
void |
setIdAttributeNS(String namespaceURI, String localName, boolean isId)
如果参数
isId 是
true ,这个方法声明指定的属性是用户自定义的ID属性。
|
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
String getTagName()
Node.localName
不同于
null
,这个属性是一个合格的名字。例如,在
< elementexample id =“演示”>…< / elementexample >,
tagName
有价值
"elementExample"
。注意,这是案例保存在XML中,当所有的DOM操作。HTML DOM返回在规范的大写形式的HTML元素的
tagName
,无论案件在HTML源文件。
String getAttribute(String name)
name
-属性名称检索。
Attr
值作为一个字符串,或空字符串,如果属性没有指定或默认值。
void setAttribute(String name, String value) throws DOMException
Attr
节点加上任何
Text
和
EntityReference
节点,构建相应的子树,并使用
setAttributeNode
指定它作为一个属性的值。
setAttributeNS
方法。
name
-属性来创建或更改名称。
value
值设置为字符串形式。
DOMException
- invalid_character_err:如果根据在使用中的
Document.xmlVersion
属性指定的XML版本指定的名称不是一个XML的名字了。
void removeAttribute(String name) throws DOMException
Document.normalizeDocument()
保证这些信息是最新的默认值。
removeAttributeNS
方法。
name
-属性的名称删除。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
Attr getAttributeNode(String name)
getAttributeNodeNS
方法。
name
-名称(
nodeName
)的属性来检索。
Attr
节点(
nodeName
)或
null
如果没有这样的属性。
Attr setAttributeNode(Attr newAttr) throws DOMException
nodeName
)已经存在的元素,它是由新的代替。用自己替换一个属性节点没有效果。
setAttributeNodeNS
方法。
newAttr
-
Attr
节点添加到属性表。
newAttr
属性将取代现有的属性,更换
Attr
节点返回,否则返回
null
。
DOMException
- wrong_document_err:如果
newAttr
是从一个比创建元素的不同文件创建了。
newAttr
已经是另一个对象的一个属性,提出
Element
。DOM节点的用户必须显式地克隆
Attr
重复使用在其他元素。
Attr removeAttributeNode(Attr oldAttr) throws DOMException
Attr
节点的默认值是在DTD中定义,一个新的节点立即出现与默认值以及对应的命名空间URI、本地名称和前缀适用时。实施可以处理从其它模式类似但应用程序应使用
Document.normalizeDocument()
保证这些信息是最新的默认值。
oldAttr
-
Attr
节点从属性列表中删除。
Attr
节点被删除。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
oldAttr
不是一个元素的属性了。
NodeList getElementsByTagName(String name)
NodeList
所有后裔
Elements
与给定的标签名称,在文档顺序。
name
-标记的名称匹配。特殊值“*”匹配所有标签。
Element
节点列表匹配。
String getAttributeNS(String namespaceURI, String localName) throws DOMException
namespaceURI
-属性来检索命名空间URI。
localName
-属性的本地名称。
Attr
值作为一个字符串,或空字符串,如果属性没有指定或默认值。
DOMException
- not_supported_err:可提高如果实现不支持此功能
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException
qualifiedName
前缀部分,其值改为
value
参数。此值是一个简单的字符串,它没有被解析为它被设置。因此,任何标记(如语法被确认为实体引用)被视为文本文本,并需要适当地逃避执行时,它被写出来。为了指定一个属性值包含实体引用,用户必须创建一个
Attr
节点加上任何
Text
和
EntityReference
节点,构建相应的子树,并使用
setAttributeNodeNS
或
setAttributeNode
指定它作为一个属性的值。
null
作为方法的
namespaceURI
参数如果他们希望没有命名空间。
namespaceURI
-属性来创建或修改命名空间URI。
qualifiedName
-属性来创建或更改名称。
value
-设置为字符串形式的价值。
DOMException
- invalid_character_err:如果根据在使用中的
Document.xmlVersion
属性指定的XML版本指定的名称不是XML的名字了。
qualifiedName
XML规范畸形每命名空间提出,如果
qualifiedName
有前缀和
namespaceURI
是
null
,如果
qualifiedName
有前缀是“XML”和
namespaceURI
不同于“
http://www.w3.org/XML/1998/namespace”,如果
qualifiedName
或它的前缀是“xmlns”和
namespaceURI
不同“
http://www.w3.org/2000/xmlns/”,或者是“z-ba928b34-37bd-4e48-9b06
namespaceURI
—d2cd61ba64d0”既不是
qualifiedName
和前缀是“xmlns”。
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
void removeAttributeNS(String namespaceURI, String localName) throws DOMException
Document.normalizeDocument()
保证这些信息是最新的默认值。
null
作为方法参数的
namespaceURI
。
namespaceURI
-属性删除命名空间URI。
localName
-属性的本地名称删除。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException
namespaceURI
-属性来检索命名空间URI。
localName
-属性的本地名称检索。
Attr
节点指定属性的本地名称和命名空间URI或
null
如果没有这样的属性。
DOMException
- not_supported_err:可提高如果实现不支持此功能
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
Attr setAttributeNodeNS(Attr newAttr) throws DOMException
null
作为方法的
namespaceURI
参数如果他们希望没有命名空间。
newAttr
-
Attr
节点添加到属性表。
newAttr
属性具有相同的本地名称和命名空间URI将取代现有的属性,更换
Attr
节点返回,否则返回
null
。
DOMException
- wrong_document_err:如果
newAttr
是从一个比创建元素的不同文件创建了。
newAttr
已经是另一个对象的一个属性,提出
Element
。DOM节点的用户必须显式地克隆
Attr
重复使用在其他元素。
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException
NodeList
所有后代
Elements
与给定的本地名称和命名空间URI。
namespaceURI
-元素的命名空间URI匹配。特殊值“*”匹配所有的命名空间。
localName
-元素的本地名称匹配。特别值“*”匹配所有的本地名称。
NodeList
对象包含所有匹配的
Elements
。
DOMException
- not_supported_err:可提高如果实现不支持此功能
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
boolean hasAttribute(String name)
true
时返回具有给定名称的属性指定这个元素或具有默认值,否则
false
。
name
-属性的名字找。
true
如果具有给定名称的属性是该元素指定或默认值,否则
false
。
boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException
true
时返回与给定的本地名称和命名空间URI属性指定该元素或具有默认值,否则
false
。
null
作为方法的
namespaceURI
参数如果他们希望没有命名空间。
namespaceURI
-属性查找命名空间URI。
localName
-本地的属性名字找。
true
如果与给定的本地名称和命名空间URI属性指定或对该元素的默认值,否则
false
。
DOMException
- not_supported_err:可提高如果实现不支持此功能
"XML"
通过文件暴露了语言不支持XML命名空间(如[
HTML 4.01 ])。
TypeInfo getSchemaTypeInfo()
void setIdAttribute(String name, boolean isId) throws DOMException
isId
是
true
,这个方法声明指定的属性是用户自定义的ID属性。这会影响
Attr.isId
价值和
Document.getElementById
的行为,但不改变,可能在使用任何模式,特别是这并不影响指定的
Attr
节点
Attr.schemaTypeInfo
。使用价值
false
为参数
isId
到undeclare属性是用户自定义的ID属性。
setIdAttributeNS
方法。
name
-属性的名称。
isId
-属性是否是一个类型的ID。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException
isId
是
true
,这个方法声明指定的属性是用户自定义的ID属性。这会影响
Attr.isId
价值和
Document.getElementById
的行为,但不改变,可能在使用任何模式,特别是这并不影响指定的
Attr
节点
Attr.schemaTypeInfo
。使用价值
false
为参数
isId
到undeclare属性是用户自定义的ID属性。
namespaceURI
-属性的命名空间URI。
localName
-属性的本地名称。
isId
-属性是否是一个类型的ID。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException
isId
是
true
,这个方法声明指定的属性是用户自定义的ID属性。这会影响
Attr.isId
价值和
Document.getElementById
的行为,但不改变,可能在使用任何模式,特别是这并不影响指定的
Attr
节点
Attr.schemaTypeInfo
。使用价值
false
为参数
isId
到undeclare属性是用户自定义的ID属性。
idAttr
-属性节点。
isId
-属性是否是一个类型的ID。
DOMException
- no_modification_allowed_err:如果这个节点是只读了。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.