Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete XML comments

Tags:

xml

vbscript

I wrote a VBScript to remove all the comments in a XML file. But it didn't work correctly. The script reads from a .xml file, generates a XML file which removes comments and another temp XML file.

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
like image 943
Rui Lu Avatar asked Apr 21 '26 20:04

Rui Lu


1 Answers

You can try with something like

With WScript.CreateObject("msxml2.DOMDocument.6.0")
    .Async = False
    .Load "in.xml"
    .SelectNodes("//comment()").RemoveAll
    .Save "out.xml"
End With 
like image 153
MC ND Avatar answered Apr 23 '26 11:04

MC ND