Fix Invalid Characters in XML File with

In the workplace you probably use XML files quite a bit. Java based xml files can produce some tricky situations where there are invisible or invalid characters exist and you need to clean them up prior to using dataset.readxml. I racked my brain for a while but came up with this method to remove those characters. I figured out what the problem was when I opened the xml file in notepad and noticed the square windows uses to represent characters it does not know what to do with. Hope it helps someone.

Public Function CleanString(ByVal s As String) As String
        Dim st As String = s
        For i As Integer = 0 To 7
            st = st.Replace(Chr(i), "")
        For i As Integer = 11 To 12
            st = st.Replace(Chr(i), "")
        For i As Integer = 14 To 31
            st = st.Replace(Chr(i), "")
        Return st
    End Function

Consulting Requests


Blog Front Page

Technorati Tags: ,,,,,,,,,,,,

Windows Live Tags:,.NET Framework,csharp,XML,Fix,Invalid,Characters,File,files,Java,notepad,Replace,situations


  1. #1 by Simon on June 11, 2009 - 8:01 am

    That seems to have worked for my project.Thanks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: