Je suis en train d'analyser un fichier xml:Pourquoi XElement tombe-t-il en analysant un fichier xml avec un xmlns?
<?xml version="1.0" encoding="utf-8" ?>
<Root>
<att1 name="bob" age="unspecified" xmlns="http://foo.co.uk/nan">
</att1>
</Root>
En utilisant le code suivant:
XElement xDoc= XElement.Load(filename);
var query = from c in xDoc.Descendants("att1").Attributes() select c;
foreach (XAttribute a in query)
{
Console.WriteLine("{0}, {1}",a.Name,a.Value);
}
Rien est écrit à la console, sauf si je supprime xmlns = "http: // foo. co.uk/nan "du fichier xml, après quoi, j'obtiens une liste de noms d'attributs et de valeurs comme on pourrait s'y attendre, et comme j'en ai besoin!
Édition: formatage.
Par ailleurs, il n'y a pas de point par écrit 'de c quelle que soit sélectionnez c'. – SLaks
Donc il n'y en a pas! Merci :) Je l'ai choisi à partir d'une introduction très utile à LINQ to XML ici: http://www.microsoft.com/uk/msdn/nuggets/nugget/204/Querying-XML-in-C-with- LINQ-to-XML.aspx – zotty