Estoy tratando de leer un archivo xml de la web y analizarlo con XDocument. Normalmente funciona bien, pero a veces me da este error para el día:'', valor hexadecimal 0x1F, es un carácter no válido. Línea 1, posición 1
**' ', hexadecimal value 0x1F, is an invalid character. Line 1, position 1**
He intentado algunas soluciones de Google, pero no están trabajando para VS 2010 Express Windows Phone 7.
Hay una solución que reemplaza el carácter 0x1F por string.empty pero mi código devuelve una secuencia que no tiene método de reemplazo.
s = s.Replace(Convert.ToString((byte)0x1F), string.Empty);
Aquí está mi código:
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;
}
}
archivo XML: http://music.mobion.vn/api/v1/music/userstop?devid=
¿Podría intentar publicar el contenido XML también? –
He intentado esto pero no funcionó, aún así me da ese error: s = s.Replace (Convert.ToString ((byte) 0x1F), string.Empty); Stream str = new MemoryStream (UTF8Encoding.UTF8.GetBytes (s)); –
aquí está el archivo xml del que trato de leer: http://music.mobion.vn/api/v1/music/userstop?devid= –