我写了一个 VBScript 来删除 XML 文件中的所有注释。但它没有正常工作。该脚本从一个 .xml 文件中读取,生成一个删除注释的 XML 文件和另一个临时 XML 文件。
Set argus = WScript.Arguments
If argus.Count = 0 Then
WScript.Quit
End If
Set fs = CreateObject("Scripting.FileSystemObject")
Set f_tu = fs.opentextfile(argus(0), 1, True)
Set f_tun = fs.opentextfile(argus(1), 2, True)
Set re_start = New RegExp
' re_start.Pattern="<!--.*-->"
re_start.Pattern="<!--"
' <!--.*|
re_start.IgnoreCase = False
re_start.Global = False
Setre_end = New RegExp
re_end.Pattern = "-->"
re_end.IgnoreCase = False
re_end.Global = False
Do While f_tu.AtEndOfStream <> True
data = f_tu.ReadLine
If re_start.Test(data) Then
Do While f_tu.AtEndOfStream <> True
data = f_tu.ReadLine
If re_end.Test(data) Then
Exit Do
End If
Loop
MsgBox data
Else
dataset = dataset+1
f_tun.WriteLine data
End If
Loop
f_tu.Close
f_tun.Close
最佳答案
你可以试试类似的东西
With WScript.CreateObject("msxml2.DOMDocument.6.0")
.Async = False
.Load "in.xml"
.SelectNodes("//comment()").RemoveAll
.Save "out.xml"
End With
关于xml - 如何删除 XML 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39609467/