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)
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)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“jscript与vbscript 操作XML元素属性的代码”评论...
更新日志
2024年11月01日
2024年11月01日
- Dragon Beauties小龙女《爱的奇迹》[320K/MP3][30.85MB]
- 魔兽世界奥杜尔团本竞速赛奖金有多少 奥杜尔团本竞速赛奖金介绍
- 暗喻幻想大沙虫巢穴怎么过 暗喻幻想大沙虫巢穴收集攻略
- 暗喻幻想食人洞穴怎么过 暗喻幻想食人洞穴收集攻略
- 锦绣二重唱《情比姊妹深》[原抓WAV+CUE]
- 碧娜《别太晚回家》[原抓WAV+CUE]
- 伽菲珈而《响往Vol.1》24K金碟限量首版[原抓WAV+CUE]
- 《超级马里奥派对:空前盛会》新作解锁!发售宣传片现已公开
- 任天堂Switch公布8周年:新主机何时来?
- 玩家反馈Switch固件更新有严重问题!待机过热 耗电多
- 唐俪.2023-月下再相逢【豪记】【WAV+CUE】
- 群星.2000-杨贵妃主题曲原声大碟【环球】【WAV+CUE】
- 钟镇涛.1994-情歌对唱集·寂寞【飞碟】【WAV+CUE】
- B10Y《We Are B10Y》[320K/MP3][250.22MB]
- B10Y《We Are B10Y》[FLAC/分轨][640.5MB]