用户登录
用户注册

分享至

jscript与vbscript 操作XML元素属性的代码

  • 作者: 采木耳的老男孩
  • 来源: 51数据库
  • 2021-07-02
although attributes belong to a particular element, they are not considered child nodes of element nodes. instead, they behave more like properties of ixmldomelement.

most of the methods for working with attributes come from ixmldomelement. attributes can be manipulated in the following ways.

directly, through the getattribute and setattribute methods of ixmldomelement.

as named ixmldomattribute nodes, with getattributenode and setattributenode.

as a set of nodes accessible through the attributes property and returned as an ixmlnamednodemap.

examples
jscript
the following jscript example creates a new document containing a <memo> element, and then creates an attribute named author with a value of "pat coleman".


vbscript


if you prefer to work with attribute nodes, you can create the attribute, and then create a text node to store its value. attribute nodes can only contain text nodes and entity reference nodes. (if you need to create an attribute containing an entity reference, you must use this approach.)

working with attribute nodes requires using the domdocument object to create attribute and text (and entity reference, if necessary) nodes before assigning the nodes to the element.

jscript
the following jscript code uses this approach to perform the same work as the preceding examples, creating a <memo> element with an author attribute holding the value "pat coleman".



vbscript
软件
前端设计
程序设计
Java相关