HappyHarry | chez moi le code suivant fonctionne, donc a part le writer que j'ai utilisé qui semble être différent ...
Code :
- using System;
- using System.Collections;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- namespace ConsoleApplication1
- {
- class Class1
- {
- [STAThread]
- static void Main(string[] args)
- {
- try
- {
- XmlTextWriter writer = new XmlTextWriter("C:\\\\toto.xml",System.Text.Encoding.Default);
- XmlSerializer classeSerializer=new XmlSerializer(typeof(Classe));
- classeSerializer.Serialize(writer, Classe.GetClasseSample() );
- }
- catch(Exception e)
- {
- Console.WriteLine(e.Message);
- if(e.InnerException != null)
- Console.WriteLine(e.InnerException.Message);
- }
- finally
- {
- Console.WriteLine("Fin." );
- Console.ReadLine();
- }
- }
- }
- [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
- [XmlInclude(typeof(Eleve))]
- public class Classe
- {
- [System.Xml.Serialization.XmlElementAttribute("Eleve", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
- public ArrayList _eleves;
- [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
- public String _niveau;
- public Classe()
- {
- this._eleves = new ArrayList();
- this._niveau = "";
- }
- public Classe(string niveau, Eleve toto)
- {
- this._niveau = niveau;
- this._eleves = new ArrayList();
- this._eleves.Add(toto);
- }
- public static Classe GetClasseSample()
- {
- return new Classe("CP",Eleve.GetEleveSample());
- }
- }
- public class Eleve
- {
- [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
- public String _nom;
- [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
- public String _prenom;
- [System.Xml.Serialization.XmlElementAttribute("Notes", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
- public ArrayList _notes;
- public Eleve()
- {
- this._nom = "";
- this._prenom = "";
- this._notes = new ArrayList();
- }
- public Eleve(string nom, string prenom, ArrayList notes)
- {
- this._nom = nom;
- this._prenom = prenom;
- this._notes = notes;
- }
- public static Eleve GetEleveSample()
- {
- return new Eleve("DUGLAND","Toto",null);
- }
- }
- }
|
Message édité par HappyHarry le 17-11-2003 à 19:59:06
|