vbs创建xml文件

上一篇 / 下一篇  2014-04-29 19:55:21 / 个人分类:VBScript

 '创建xml对象51Testing软件测试网,t/`0D}!F
51Testing软件测试网V3K aK}8O/| ^z

set xmldoc=createobject("Microsoft.XMLDOM")
Z|1_#D/br W0'取消异步加载51Testing软件测试网o(I}8{;Y:I'gO
xmldoc.async=false
hQa"ED?cw t0'创建处理指令
z P^_7k!oDW8F0
1b$UL&s&cos%?*x0set newPI=xmldoc.createProcessingInstruction("xml","version='1.0'encoding='utf-8'")51Testing软件测试网.uj?3FW
xmldoc.appendchild(newPI)51Testing软件测试网 wq Wfi/v$lH!G
'创建根节点
yL.TC:o)F ign0set doc=xmldoc.createelement("userinfo")51Testing软件测试网P1~B|-PB!Es4j+{9N
'创建CDATA节点51Testing软件测试网1b&~6g:rV6x4T;e/N0r(j
set newCD=xmldoc.createCDATASection("this is a CDDATA")
Es S2?.I'WYOw![0doc.appendchild("newCD")
k6S)~4eb.`]{0'创建注释51Testing软件测试网+K"I%^UL$~R*k xq
set newcomment=xmldoc.createcomment("comment")51Testing软件测试网Sr Sh&g+^ lx%vg
doc.appendchild(newcomment)51Testing软件测试网a D#h+N a-c(s
'创建元素节点
k.oL0Sa~/oFx0set newnode=xmldoc.createelemet("user")51Testing软件测试网u,?T8P Q` N
set newnode2=xmldoc.createelement("name")
|T)e^IA2m0'创建文本节点51Testing软件测试网8e+z+f [z#q_8m L
set textnode=xmldoc.createelement("jhon")51Testing软件测试网O*\(R/X:~:vf
newnode2.appendchild(textnode)51Testing软件测试网ZN$R`SC4k
newnode.appendchild(newnode2)
;_{ |.V)|(Mn0'创建属性
/k4g,tKgu*]6kn;a0set newattr=xmldoc.createattribute("id")
eoeZ'Y|0newattr.value="20140429"51Testing软件测试网 As5uv'W? j(}6n8vq
newnode.setatributenode(newattr)
BE,o@lidu wr4Y0doc.appendchild(newnode)51Testing软件测试网4lGU}&d WI
xmldoc.appendchild(doc)
TYlia'pT-v051Testing软件测试网N&O8m:LD(_~
on error resume next51Testing软件测试网-G,g!c3]8KuDC d
xmldoc.save "d:\sample.xml"
1u4\)~7N7_w0c0if err.number<>0 then
} yt W.N_0msgbox err.description
A+w$me)_} K0else
2@+J$W7t@-sm}X0msgbox "创建xml成功"51Testing软件测试网6\Iz\&a}
end if

uB Gl @Xdp0

TAG:

 

评分:0

我来说两句

Open Toolbar