十六进制值0x1F的,是无效字符 [英] hexadecimal value 0x1F, is an invalid character
本文介绍了十六进制值0x1F的,是无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误:
,十六进制值0x1F的,是无效字符
下面是我的功能。我得到这个错误,当它击中reader.MoveToContent()的第一次。任何人都可以点我在正确的方向?
公共功能GetSyndicationFeedData(BYVAL urlFeedLocation作为字符串)作为SyndicationFeed 昏暗的设置作为新XmlReaderSettings(){带_
.IgnoreWhitespace = TRUE,_
.CheckCharacters = TRUE,_
.CloseInput = TRUE,_
.IgnoreComments = TRUE,_
.IgnoreProcessingInstructions =真_
} 如果[字符串] .IsNullOrEmpty(urlFeedLocation)然后
什么都不返回
万一 使用阅读器的XmlReader = XmlReader.Create(urlFeedLocation,设置)
如果reader.ReadState = ReadState.Initial然后
reader.MoveToContent()
万一 现在尝试阅读...
昏暗的原子作为新Atom10FeedFormatter()
昏暗rss20作为新Rss20FeedFormatter() 凌动
如果atom.CanRead(阅读器)然后
atom.ReadFrom(阅读器)
返回atom.Feed
RSS 2.0
elseif的rss20.CanRead(阅读器)然后
rss20.ReadFrom(阅读器)
返回rss20.Feed
其他
什么都不返回
万一
使用完
结束功能
解决方案
您可以使用以下code(抱歉,但它是在C#)下载饲料及更换有问题的字符。
VAR的客户=新的WebClient();
VAR feedAsString = client.DownloadString(urlFeedLocation).Replace((炭)(0x1F的),Convert.ToChar());
使用(读者的XmlReader = XmlReader.Create(新的MemoryStream(Encoding.Default.GetBytes(feedAsString)),设置))
{
//你的code的剩余部分在这里
}
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
解决方案
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
}
这篇关于十六进制值0x1F的,是无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文