以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  怎样设置节点的属性?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=32679)


--  作者:junge_003
--  发布时间:5/19/2006 10:53:00 AM

--  怎样设置节点的属性?
一个节点具有多个属性比如<node name="node" id="2">
这样的节点属性怎么设置啊?
用哪个方法?
--  作者:flyfoxs
--  发布时间:5/19/2006 12:58:00 PM

--  
如果是用java语言的话,

Element提供了如下方法,不过由于DOM是一个标准,很多语言都支持到了2级别,操作起来应该是一样的。


public void setAttribute(String name,
                         String value)
                  throws DOMException
Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter. This value is a simple string; it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNode to assign it as the value of an attribute.
To set an attribute with a qualified name and namespace URI, use the setAttributeNS method.

Parameters:
name - The name of the attribute to create or alter.
value - Value to set in string form.
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified name contains an illegal character.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
4,837.891ms