Whenever I'm trying to read the XML, I get this error-
"An XML comment cannot contain '--', and '-' cannot be the last character"
Is there anyway, I can remove all comments? The file is very long to remove it manually.
Printable View
Whenever I'm trying to read the XML, I get this error-
"An XML comment cannot contain '--', and '-' cannot be the last character"
Is there anyway, I can remove all comments? The file is very long to remove it manually.
You can read the file as a text file, check each line in a loop and write a new file skipping over the lines or portions of lines you do not want.
Here is something I threw together real quick:
Don't forget -Code:Sub Main()
Dim file As String = "D:\file.xml"
Dim line As String
Dim lines As New List(Of String)
Using sr As StreamReader = New StreamReader(file)
While Not sr.EndOfStream
line = sr.ReadLine
If line.Trim.StartsWith("<!--") Then Continue While 'Check if the comment is on its own line
line = Regex.Replace(line, "(<!--.*?--\>)", String.Empty) 'Removes comments if they are anywhere else on the line
lines.Add(line)
End While
End Using
Using sw As StreamWriter = New StreamWriter(file)
For Each rdyLines As String In lines
sw.WriteLine(rdyLines)
Next
End Using
End Sub
Imports System.IO
Imports System.Text.RegularExpressions