Leggere un file xml ed utilizzo di XmlNameSpaceManager

venerdì 26 aprile 2013 - 10.28
Tag Elenco Tags  C#  |  .NET 4.0

svipla Profilo | Senior Member

Ciao a tutti
devo leggere il file xml di youtube con tutte le categorie dei video.
Il file ha questa struttura:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<app:categories xmlns:app=\"http://www.w3.org/2007/app\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\" fixed=\"yes\" scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">
<atom:category term=\"Film\" label=\"Film e animazione\" xml:lang=\"it-IT\">
<yt:assignable />
<yt:browsable regions=\"AE AR AT AU BD BE BG BH BR CA CH CL CO CZ DE DK DZ EE EG ES ET FI FR GB GH GR HK HR HU ID IE IL IN IR IS IT JO JP KE KR KW LT LV MA MX MY NG NL NO NZ OM PE PH PK PL PT QA RO RS RU SA SE SG SI SK SN TH TN TR TW TZ UA UG US VN YE ZA\" />
</atom:category>
...
</app:categories>

Fino ad oggi per leggere un file xml ho utilizzato questo codice:

WebRequest myRequest = WebRequest.Create(urlCategoryList);
WebResponse myResponse = myRequest.GetResponse();

Stream stream = myResponse.GetResponseStream();
XmlDocument doc = new XmlDocument();
doc.Load(stream);

XmlNodeList items = doc.SelectNodes("app:categories/atom:category");
foreach (XmlNode item in items)
{
tipoYouTubeCategory categoria = new tipoYouTubeCategory();
categoria.Term = item.Attributes["term"].ToString();
categoria.Label = item.Attributes["label"].ToString();

categorie.Add(categoria);
}

ma ora ricevo questo errore:

Richiesto gestore dello spazio dei nomi o XsltContext. Query con prefisso, variabile o funzione definita dall'utente.

Ho trovato in rete una possibile soluzione che suggerisce di utilizzare la classe XmlNameSpaceManager , ma non ci ho capito molto.

Grazie mille
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5