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

时间:2012-06-25 02:03:30

标签: asp.net xml vb.net rss

我收到以下错误:

'',十六进制值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

1 个答案:

答案 0 :(得分:2)

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

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
}