vbs创建xml文件

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

 '创建xml对象
2kf%I@j%v0M0
51Testing软件测试网g5uB7P.FF"O-^v

set xmldoc=createobject("Microsoft.XMLDOM")51Testing软件测试网e2zw ^+^9K
'取消异步加载
Gk/U'W+p0xmldoc.async=false
]bVN f.H0'创建处理指令
^-k-ob%vc0
R`f:`,DAN0set newPI=xmldoc.createProcessingInstruction("xml","version='1.0'encoding='utf-8'")51Testing软件测试网#W2r"C#Q#s A/U3a
xmldoc.appendchild(newPI)
O,w9z G F5kZ0'创建根节点51Testing软件测试网S0n0{ZDJU)P VXZ
set doc=xmldoc.createelement("userinfo")51Testing软件测试网x(o,X,??\W3Cc~%] f
'创建CDATA节点
!_ q"M] AC9QX0set newCD=xmldoc.createCDATASection("this is a CDDATA")
`t? GOw6H"]0doc.appendchild("newCD")51Testing软件测试网1S3rs\#y.[!f
'创建注释
u6i9e(p7f0set newcomment=xmldoc.createcomment("comment")
lXA/M7KcK0doc.appendchild(newcomment)51Testing软件测试网zQhQN
'创建元素节点51Testing软件测试网D&T/m!je8`&\^n
set newnode=xmldoc.createelemet("user")51Testing软件测试网,QW$IC;HI&g0t+K3VJ
set newnode2=xmldoc.createelement("name")51Testing软件测试网g KdS T;\
'创建文本节点51Testing软件测试网*d E.Wm \&|
set textnode=xmldoc.createelement("jhon")
:Y0|6Uq:k3N0f6MH0newnode2.appendchild(textnode)
-Iy%w9jG|$u"U0newnode.appendchild(newnode2)51Testing软件测试网oQ&_d#W
'创建属性
Z G9H/U n4K"R"Dau-p0set newattr=xmldoc.createattribute("id")51Testing软件测试网d/r A0OP0LHS
newattr.value="20140429"
-^/r&l.l(ed0newnode.setatributenode(newattr)
(oi}1b{KbNU%w|0doc.appendchild(newnode)
)O;T@ iL3O0xmldoc.appendchild(doc)51Testing软件测试网.J-N ^USo b.rf/U9|
51Testing软件测试网 h0gs.X'V,v3gp
on error resume next
i3Wp*aWa7S0xmldoc.save "d:\sample.xml"
V8Js5vA'g'B7`:j0if err.number<>0 then51Testing软件测试网 J:G$e+F7rcv
msgbox err.description51Testing软件测试网(Z$W/Kzh.X h^/_ a
else51Testing软件测试网#bM`$U;M.G6g#U)\/b
msgbox "创建xml成功"
Y2k6Ed&?0end if

zn pk9Z'{0

TAG:

 

评分:0

我来说两句

Open Toolbar