[LINQ TO XML][C#] NullReference
Bonjour
j'aurai besoin d'un coup de main voici mon code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
public class ProfilTFS
{
public String Name { get; set; }
public String Code { get; set; }
public String Description { get; set; }
public List<DroitTFS> Droits { get; set; }
}
public class DroitTFS
{
public String Name { get; set; }
public String Group { get; set; }
public String Role { get; set; }
}
}
var profils = (from profil in xmlproc.Descendants("Profil")
where (profil.IsEmpty == false)
select new ProfilTFS
{
Name = profil.Attribute("Name").Value.ToString(),
Code = profil.Attribute("Code").Value.ToString(),
Description = profil.Attribute("Description").Value.ToString(),
Droits = (
from droit in profil.Elements("Droit")
where ( droit.IsEmpty == false)
select new DroitTFS
{
Name = droit.Attribute("Name").Value.ToString(),
Group = droit.Attribute("Group").Value.ToString(),
Role = droit.Attribute("Role").Value.ToString()
}
).ToList<DroitTFS>()
}
); |
il me sert à lire le fichier Xml suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?xml version="1.0" standalone="yes" ?>
<root>
<Profils>
<Profil Name="EveryOne" Code="EVO">
<Droit Name="SharePoint" Group="Visiteur du portail" />
<Droit Name="Reporting Services" Role="Browser" />
</Profil>
<Profil Name="Chef de Projet" Code="CDP" Description="Groupe contenant tous les chefs de projets du projet.">
<Droit Name="SharePoint" Group="Membres du portail" />
<Droit Name="Reporting Services" Role="Browser,Publisher" />
</Profil>
<Profil Name="Testeurs" Code="TST" Description="Groupe contenant tous les testeurs du projet.">
<Droit Name="SharePoint" Group="Membres du portail" />
<Droit Name="Reporting Services" Role="Browser,Publisher" />
</Profil>
<Profil Name="Release Manager" Code="RM" Description="Groupe contenant tous les release manager du projet.">
<Droit Name="SharePoint" Group="Membres du portail" />
<Droit Name="Reporting Services" Role="Browser,Publisher" />
</Profil>
</Profils>
</root> |
Malheureusement j'obtiens le message d'erreur suivant
Citation:
{"La référence d'objet n'est pas définie à une instance d'un objet."}