当前位置: 移动技术网 > IT编程>网页制作>XML > jscript与vbscript 操作XML元素属性的代码

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

2017年12月01日  | 移动技术网IT编程  | 我要评论
although attributes belong to a particular element, they are not considered child node
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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网