0

我收到以下错误:

' ',十六进制值 0x1F,是无效字符

这是我的功能。第一次点击“reader.MoveToContent()”时出现此错误。谁能指出我正确的方向?

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
4

1 回答 1

2

您可以使用以下代码(抱歉,它在 c# 中)下载提要并替换有问题的字符。

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
}
于 2012-06-25T04:28:11.807 回答