The system does not support 'iso-8859-1' encoding

S

Sergey Bogdanov

This encoding is not supported (actually the XmlException.Message shows
it). If it possible, it would be better to switch to UTF-8 encoding.
 
N

Nathan Mellor

I don't control the source data.

I would need to either convert the file elsewhere or somehow ignore the tag
and treat it as UTF-8, since it may be labelled incorrectly anyway.

Certainly not very elegant. But may be the best I can do.

Nathan
 
Joined
Sep 22, 2005
Messages
1
Reaction score
0
Nathan,

I was having the same problem, and I also suspected that the encoding was actually okay and the XML was just tagged incorrectly. I created the following function which replaces the ISO-8859-1 tag with a UTF-8 tag. After that, the XML Document processor worked perfectly. Admittedly, this function is a hack, woefully inefficient, and error-prone, but it's a starting point, and it got me past this annoying issue. Hopefully this will help someone else as well.

Public Function DownloadToXML(ByVal p_URL As String) As System.Xml.XmlDocument
Dim l_WebRequest As WebRequest
Dim l_XMLDoc As XmlDocument
Dim l_Stream As Stream

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor

Try
l_WebRequest = System.Net.HttpWebRequest.Create(p_URL)
l_Stream = l_WebRequest.GetResponse.GetResponseStream()
l_XMLDoc = New System.Xml.XmlDocument
l_XMLDoc.Load(ConvertISO8859ToUTF8(l_Stream))
Catch ex As Exception
MsgBox("Unable to download XML: " & ex.Message.ToString)
End Try

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default

Return l_XMLDoc

End Function

Private Function ConvertISO8859ToUTF8(ByVal p_Stream As Stream) As Stream
Dim l_StreamOut As New MemoryStream
Dim l_StreamReader As New StreamReader(p_Stream)
Dim l_StreamWriter As New StreamWriter(l_StreamOut)
Dim l_Line As String

l_Line = l_StreamReader.ReadLine()
If (Not l_Line Is Nothing) Then
l_Line = Replace(l_Line, "encoding=""ISO-8859-1""", "encoding=""UTF-8""")
l_StreamWriter.WriteLine(l_Line)
End If
Do
l_Line = l_StreamReader.ReadLine()
If (Not l_Line Is Nothing) Then
l_StreamWriter.WriteLine(l_Line)
End If
Loop Until l_Line Is Nothing
l_StreamReader.Close()
l_StreamWriter.Flush()
l_StreamOut.Seek(0, SeekOrigin.Begin)

Return l_StreamOut

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top