Although attributes bel ong to a particular eleme nt, they are not con sidered chi ld no des of element no des. In stead, they behave more l ike properties of IXMLDOMEIeme nt.
Most of the methods for work ing with attributes come from IXMLDOMEleme nt.Attributes can bemani pulated in the fol lowi ng ways.
Directly, through the getAttribute and setAttribute methods of IXMLDOMEleme nt.
As named IXMLDOMAttribute nodes,with getAttributeNode and setAttributeNode.
As a set of no des accessible through the attributes property and retur ned as an
IXMLNamedNodeM ap.
Examples
JScript
The fol low ing JScript example creates a new docume nt containing a<mem o>eleme nt,and the n creates an attribute n amed author with a value of "Pat Colema n".
代码如下var xmlDoc=new ActiveXObject("Msxml2.DOMDocume nt.3.0");var rootEleme nt=xmlDoc.createEleme nt("memo");rootEleme nt.setAttribute("author", "Pat Colema n");xmlDoc.appe ndChi ld(rootEleme nt);
VBScript
代码如下
Set xmlDoc=CreateObject("Msxml2.DOMDocume nt.3.0")
Set rootEleme nt=xmlDoc.createEleme nt("memo")rootEleme nt.setAttribute("author", "Pat Colema n")xmlDoc.appe ndChi ld(rootEleme nt)
If you prefer to work with attribute no des,you can create the attribute,and the n create a textnode to store its value.Attribute no des can only contain text no des and en tity reference no des. (If youn eed to create an attribute containing an en tity reference,you must use this approach.)
Worki ng with attribute no des requires using the DOMDocume nt object to create attribute andtext (a nd en tity referen ce, if n ecessary)no des before assig ning the no des to the eleme nt.
JScript
The fol lowi ng JScript code uses this approach to perform the same work as the precedi ngexamples,creating a<memo>element with an author attribute holding the value"Pat Colema n".
代码如下var xmlDoc=new ActiveXObject("Msxml2.DOMDocume nt.3.0");var rootEleme nt=xmlDoc.createEleme nt("memo");var memoAttribute=xmlDoc.createAttribute("author");var memoAttributeText=xmlDoc.createTextNode("Pat Colema n");memoAttribute.appe ndChi ld(memoAttributeText);rootEleme nt.setAttributeNode(memoAttribute);xmlDoc.appe ndChi ld(rootEleme nt);
VBScript
代码如下
Set xmlDoc=CreateObject("Msxml2.DOMDocume nt.3.0")
Set rootEleme nt=xmlDoc.createEleme nt("memo")
Set memoAttribute=xmlDoc.createAttribute("author")
Set memoAttributeText=xmlDoc.createTextNode("Pat Colema n")memoAttribute.appendChi ld(memoAttributeText) rootEleme nt.setAttributeNode(memoAttribute)xmlDoc.appendChi ld(rootEleme nt)
更多信息请查看IT技术专栏
香港大带宽服务器香港大带宽云服务器目前市场上可以选择的商家十分少,这次给大家推荐的是我们的老便宜提速啦的香港大带宽云服务器,默认通用BGP线路(即CN2+BGP)是由三网直连线路 中国电信骨干网以及HGC、NTT、PCCW等国际线路混合而成的高品质带宽(精品带宽)线路,可有效覆盖全球200多个国家和地区。(适用于绝大部分应用场景,适合国内外访客访问,域名无需备案)提速啦官网链接:点击进入香港Cer...
昨天我们很多小伙伴们应该都有看到,包括有隔壁的一些博主们都有发布Vultr商家新的新用户注册福利活动。以前是有赠送100美元有效期30天的,这次改成有效期14天。早年才开始的时候有效期是60天的,这个是商家行为,主要还是吸引到我们后续的充值使用,毕竟他们的体验金赠送,在同类商家中算是比较大方的。昨天活动内容:重新调整Vultr新注册用户赠送100美元奖励金有效期14天今天早上群里的朋友告诉我,两年...
Hostigger 主机商在前面的文章中也有介绍过几次,这个商家运营时间是有一些年份,只不过在我们圈内好像之前出现的次数不多。最近这段时间商家有提供不限流量的VPS主机,逐渐的慢慢被人认识到。在前面的介绍到他们提供的机房还是比较多的,比如土耳其、美国等。今天看到Hostigger 商家居然改动挺大的,原来蛮好的域名居然这次连带官方域名都更换掉去掉一个G(Hostiger )。估摸着这个域名也是之前...