|
之前在论坛里面看过有关XML文件的处理方法,附上来,可做为参考,看对楼主有没有帮助
function autoXML(ary)
On Error Resume Next
Dim xmlFile
Dim xmldoc,root,books
xmlFile = "book.xml"
Set xmldoc = WScript.CreateObject("Microsoft.XMLDOM")
xmldoc.async = false
xmldoc.load xmlFile
if xmldoc.parseError.errorCode Then
Dim xmlhead,xslhead
Set xmlhead = xmldoc.createProcessingInstruction("xml","version=""1.0"" encoding=""UTF-8""")
xmldoc.insertBefore xmlhead,xmldoc.childNodes(0)
Set xslhead = xmldoc.createProcessingInstruction("xml-stylesheet","type=""text/xsl"" href=""book.xsl""")
xmldoc.insertBefore xslhead,xmldoc.childNodes(1)
Set books = xmldoc.createElement("books")
xmldoc.appendChild books
Else
Set books = xmldoc.documentElement
End If
Dim book,nodes,node
Set book = xmldoc.createElement("book")
books.appendChild book
nodes = split("id,ISBN,book_name,writer,publish,price,img",",")
for i=0 to UBound(nodes)
Set node = xmldoc.createElement(nodes(i))
node.text = ary(i)
book.appendChild node
Next
xmldoc.save xmlFile
If Err.number<>0 Then
WScript.echo "保存失败!原因:" & Err.Description
Else
WScript.echo "《" & ary(2) & "》保存成功!"
End If
End Function
(原版作者别告我侵权哈^_^) |
|