In a perfect world my xml feed source would produce perfect xml ..that is not the case
I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing.
I've tried doing pre processing with find/replace to get rid of these characters but then I get another type of error
"An unexpected end of file parsing CDATA has occurred"
So to get around that error I've added in unicoding and removing non-printable chars with no success.
here's my code...or a summary of it
and that doesn't work either
help anyone? thanks
I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing.
I've tried doing pre processing with find/replace to get rid of these characters but then I get another type of error
"An unexpected end of file parsing CDATA has occurred"
So to get around that error I've added in unicoding and removing non-printable chars with no success.
here's my code...or a summary of it
Code:
' grab rss feed to a stream Dim myRequest As System.Net.WebRequest = System.Net.WebRequest.Create(url) Dim myResponse As System.Net.WebResponse = myRequest.GetResponse ' convert stream to string for pre-processing Dim rdr As New StreamReader(myResponse.GetResponseStream()) s = rdr.ReadToEnd 'remove non print chars s = Regex.Replace(s, "\s", " ") 'convert to unicode Dim uni As New UnicodeEncoding Dim encodedBytes As Byte() = uni.GetBytes(s) Dim decodedString As String = uni.GetString(encodedBytes) s = decodedString 'remove standalone dashes and amps s = s.Replace(" & ", " and ") s = s.Replace(" - ", " - ") 'feed the string back in a stream for the XmlTextReader Dim memoryStream As New MemoryStream Dim streamWriter As New StreamWriter(memoryStream) streamWriter.Write(s) memoryStream.Position = 0 Dim XmlReader As New XmlTextReader(memoryStream) ' start xml parsing from here
help anyone? thanks
Comment