我想從網上讀取一個xml文件並使用XDocument解析出來。它通常工作正常,但有時它給我這個錯誤的一天:'',十六進制值0x1F,是一個無效的字符。第1行,位置1
**' ', hexadecimal value 0x1F, is an invalid character. Line 1, position 1**
我試圖從谷歌的一些解決方案,但他們沒有對VS 2010速成的Windows Phone 7的工作
有一個解決方案它將0x1F字符替換爲string.empty,但是我的代碼返回一個沒有替換方法的流。
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文件: http://music.mobion.vn/api/v1/music/userstop?devid=
您可以嘗試發佈XML內容嗎? –
我已經試過這個,但沒有工作,仍然給出這個錯誤: s = s.Replace(Convert.ToString((byte)0x1F),string.Empty); Stream str = new MemoryStream(UTF8Encoding.UTF8.GetBytes(s)); –
這裏是我嘗試閱讀的xml文件: http://music.mobion.vn/api/v1/music/userstop?devid= –