Csharp ecrire dans un xml

Fermé
haloremi Messages postés 304 Date d'inscription lundi 10 mars 2008 Statut Membre Dernière intervention 6 novembre 2015 - 14 déc. 2012 à 19:20
Bonjour,
J'ai un petit soucie j'aimerai creer un fichier xml qui ressemblerai à sa :
<?xml version="1.0" encoding="utf-8"?>
<profils>
	<parametre id="defaut">
		<poids>0</poids>
		<sexe>1</sexe>
	</parametre>
	<parametre id="toto">
		<poids>51</poids>
		<sexe>1</sexe>
	</parametre>
</profils>

j'ai donc écrit dans ma fonction :
/*fot(cpt = 0; cpt < list_profil.Count ; cpt++)
                     {*/
//--------------------Première partie-----------------------------
                        XmlTextWriter.WriteStartElement("parametre");
                            XmlTextWriter.WriteAttributeString("id", list_profil[0].get_nom());
                                XmlTextWriter.WriteStartElement("poids");
                                    XmlTextWriter.WriteString(list_profil[0].get_poids());
                                XmlTextWriter.WriteEndElement();
                                XmlTextWriter.WriteStartElement("sexe");
                                    XmlTextWriter.WriteString(list_profil[0].get_sexe());
                                XmlTextWriter.WriteEndElement();
                           XmlTextWriter.WriteEndElement();
                        XmlTextWriter.WriteEndElement();
//--------------------Seconde partie-----------------------------
                        XmlTextWriter.WriteStartElement("parametre");
                            XmlTextWriter.WriteAttributeString("id", list_profil[1].get_nom());
                                XmlTextWriter.WriteStartElement("poids");
                                    XmlTextWriter.WriteString(list_profil[1].get_poids());
                                XmlTextWriter.WriteEndElement();
                                XmlTextWriter.WriteStartElement("sexe");
                                    XmlTextWriter.WriteString(list_profil[1].get_sexe());
                                XmlTextWriter.WriteEndElement();
                            XmlTextWriter.WriteEndElement();
                        XmlTextWriter.WriteEndElement();
                        
                    // }

Ma première partie fonctionne parfaitement quand j'enlève ma deuxième partie (sans compter les
XmlTextWriter.WriteEndElement();
de la première partie). Mais quand je rajoute ma seconde partie (ou une boucle) il y a une erreur à :
XmlTextWriter.WriteStartElement("parametre");

Si quelqu'un connais la solution à mon problème,
Merci de votre aide !


A voir également: