内容简介:jscript与vbscript 操作XML元素属性的代码,需要的朋友可以参考下。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".
复制代码 代码如下:
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
var rootElement=xmlDoc.createElement("memo");
rootElement.setAttribute("author", "Pat Coleman");
xmlDoc.appendChild(rootElement);
VBScript
复制代码 代码如下:
Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
Set rootElement=xmlDoc.createElement("memo")
rootElement.setAttribute("author", "Pat Coleman")
xmlDoc.appendChild(rootElement)
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".
复制代码 代码如下:
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
var rootElement=xmlDoc.createElement("memo");
var memoAttribute=xmlDoc.createAttribute("author");
var memoAttributeText=xmlDoc.createTextNode("Pat Coleman");
memoAttribute.appendChild(memoAttributeText);
rootElement.setAttributeNode(memoAttribute);
xmlDoc.appendChild(rootElement);
VBScript
复制代码 代码如下:
Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
Set rootElement=xmlDoc.createElement("memo")
Set memoAttribute=xmlDoc.createAttribute("author")
Set memoAttributeText=xmlDoc.createTextNode("Pat Coleman")
memoAttribute.appendChild(memoAttributeText)
rootElement.setAttributeNode(memoAttribute)
xmlDoc.appendChild(rootElement)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- WPF 元素裁剪 Clip 属性
- PHP的SimpleXML遍历所有子元素及访问特定节点元素和属性
- 为什么React元素有一个$$typeof属性?
- [译] 我在阅读 MDN 时发现的 3 个 Input 元素属性
- WPF 中使用附加属性,将任意 UI 元素或控件裁剪成圆形(椭圆)
- javascript – 如何使用jquery查找包含与前缀匹配的data- *属性的元素
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
谁说菜鸟不会数据分析
张文霖、刘夏璐、狄松 编著 / 电子工业出版社 / 2011-7 / 59.00元
《谁说菜鸟不会数据分析(全彩)》内容简介:很多人看到数据分析就望而却步,担心门槛高,无法迈入数据分析的门槛。《谁说菜鸟不会数据分析(全彩)》在降低学习难度方面做了大量的尝试:基于通用的Excel工具,加上必知必会的数据分析概念,并且采用通俗易懂的讲解方式。《谁说菜鸟不会数据分析(全彩)》努力将数据分析写成像小说一样通俗易懂,使读者可以在无形之中学会数据分析。《谁说菜鸟不会数据分析(全彩)》按照数据......一起来看看 《谁说菜鸟不会数据分析》 这本书的介绍吧!