如何使用VBScripting创建xml文件时添加新行?

时间:2014-03-04 09:44:03

标签: vbscript

下面是我在使用VBScripting进行自动化时使用的函数,同时在xml文件中获取结果。结果现在显示在一行中。请让我知道如何在每个“结果”节点后添加一个新行。我也无法使用“替换(字符串,vbCrLf,”“)”。它给出错误“调用函数时不能使用括号”。

Function WriteTestSet(TestSetPath, sheetname, varr )
set wb = xl.workbooks.open(TestSetPath)
set ws = wb.worksheets(sheetname)

rc = ubound(varr, 1) + 1
cc = ubound(varr, 2) + 1

Set xmlDoc = CreateObject("Microsoft.XMLDOM")  
Set objRoot = xmlDoc.createElement("TestResults")  
xmlDoc.appendChild objRoot

for m= 0 to rc-1
    for n= 0 to 0
        Set objTest = xmlDoc.createElement("TestCaseName")  
        objTest.Text = varr(m,n)
        objRoot.appendChild objTest 

        Set objRun = xmlDoc.createElement("Run")  
        objRun.Text = varr(m,n+1) 
        objRoot.appendChild objRun 

        Set objResult = xmlDoc.createElement("Results")  
        objResult.Text = varr(m,n+2) 
        objRoot.appendChild objResult
    next
next
Set objIntro = xmlDoc.createProcessingInstruction ("xml","version='1.0'")  
xmlDoc.insertBefore objIntro,xmlDoc.childNodes(3)
ts = replace(replace(now, "/", "_"), ":", "_")
xmlDoc.Save "E:\TestResults\TestSet"& ts & ".xml" 
End Function

1 个答案:

答案 0 :(得分:0)

您可以使用XSL style sheet将XML转换为适当间隔的缩进格式。

相关问题