本文介绍了'',十六进制值0x1F,是一个无效的字符。第1行,第1位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Web上读取一个xml文件,并使用XDocument解析它。它通常工作正常,但有时它给我这个错误的一天:
I am trying to read a xml file from the web and parse it out using XDocument. It normally works fine but sometimes it gives me this error for day:
**' ', hexadecimal value 0x1F, is an invalid character. Line 1, position 1**
我已经尝试过Google的一些解决方案,但没有为VS 2010 Express Windows Phone 7。
I have tried some solutions from Google but they aren't working for VS 2010 Express Windows Phone 7.
有一个解决方案将0x1F字符替换为string.empty,但是我的代码返回一个没有替换方法的流。 / p>
There is a solution which replace the 0x1F character to string.empty but my code return a stream which doesn't have replace method.
s = s.Replace(Convert.ToString((byte)0x1F), string.Empty);
这是我的代码:
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
using (var reader = new StreamReader(e.Result))
{
int[] counter = { 1 };
string s = reader.ReadToEnd();
Stream str = e.Result;
// s = s.Replace(Convert.ToString((byte)0x1F), string.Empty);
// byte[] str = Convert.FromBase64String(s);
// Stream memStream = new MemoryStream(str);
str.Position = 0;
XDocument xdoc = XDocument.Load(str);
var data = from query in xdoc.Descendants("user")
select new mobion
{
index = counter[0]++,
avlink = (string)query.Element("user_info").Element("avlink"),
nickname = (string)query.Element("user_info").Element("nickname"),
track = (string)query.Element("track"),
artist = (string)query.Element("artist"),
};
listBox.ItemsSource = data;
}
}
XML文件:
推荐答案
考虑使用,如果您正在解读从网络读取的内容。
Consider using System.Web.HttpUtility.HtmlDecode if you're decoding content read from the web.
这篇关于'',十六进制值0x1F,是一个无效的字符。第1行,第1位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!