-
June 2nd, 2012, 02:52 AM
#1
[RESOLVED] XML Comment Error.
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.
-
June 2nd, 2012, 01:57 PM
#2
Re: XML Comment Error.
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.
Always use [code][/code] tags when posting code.
-
June 11th, 2012, 05:30 PM
#3
Re: XML Comment Error.
Here is something I threw together real quick:
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
Don't forget -
Imports System.IO
Imports System.Text.RegularExpressions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|