hexadecimal value 0x1F, is an invalid character

故事扮演 提交于 2019-12-13 04:12:18

问题


I am getting the following error:

' ', hexadecimal value 0x1F, is an invalid character

Here is my function. I get this error when it hits "reader.MoveToContent()" for the first time. Can anyone point me in the right direction?

Public Function GetSyndicationFeedData(ByVal urlFeedLocation As String) As SyndicationFeed

    Dim settings As New XmlReaderSettings() With { _
      .IgnoreWhitespace = True, _
      .CheckCharacters = True, _
      .CloseInput = True, _
      .IgnoreComments = True, _
      .IgnoreProcessingInstructions = True _
    }

    If [String].IsNullOrEmpty(urlFeedLocation) Then
        Return Nothing
    End If

    Using reader As XmlReader = XmlReader.Create(urlFeedLocation, settings)
        If reader.ReadState = ReadState.Initial Then
            reader.MoveToContent()
        End If

        ' Now try reading...
        Dim atom As New Atom10FeedFormatter()
        Dim rss20 As New Rss20FeedFormatter()

        ' Atom
        If atom.CanRead(reader) Then
            atom.ReadFrom(reader)
            Return atom.Feed
            'Rss 2.0
        ElseIf rss20.CanRead(reader) Then
            rss20.ReadFrom(reader)
            Return rss20.Feed
        Else
            Return Nothing
        End If
    End Using
End Function

回答1:


You can use the following code (sorry but it is in c#) to download the feed and replace the offending character.

var client = new WebClient();
var feedAsString = client.DownloadString(urlFeedLocation).Replace((char)(0x1F), Convert.ToChar(""));
using (XmlReader reader = XmlReader.Create(new MemoryStream(Encoding.Default.GetBytes(feedAsString)), settings))
{
    // remainder of your code here
}


来源:https://stackoverflow.com/questions/11182729/hexadecimal-value-0x1f-is-an-invalid-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!