Bonjour à tous,
Je voulais savoir, comment m'y prendre pour imbriquer un ensemble de propriété de mon objet dans un élément (XmlElement), je m'explique par un exemple :
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 [Serializable()] [XmlRoot("ContactList")] public class Contact { private int _intCivilite; public int intCivilite { get { return _intCivilite; } set { _intCivilite = value; } } private string _strPrenom = "toto"; public string strPrenom { get { return _strPrenom; } set { _strPrenom = value; } } private string _strNom = "toto"; public string strNom { get { return _strNom; } set { _strNom = value; } } private string _strMethodeDeContact = "toto"; public string strMethodeDeContact { get { return _strMethodeDeContact; } set { _strMethodeDeContact= value; } } private string _strEmail = "toto"; public string strEmail { get { return _strEmail; } set { _strEmail = value; } } private string _strTelephone = "toto"; public string strTelephone { get { return _strTelephone; } set { _strTelephone = value; } } private string _strCommentaires = "toto"; public string strCommentaires { get { return _strCommentaires; } set { _strCommentaires = value; } } }
Ce qui donne :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 <contact> <intCivilite>0</intCivilite> <strPrenom>toto</strPrenom> <strNom>toto</strNom> <strMethodeDeContact>toto</strMethodeDeContact> <strEmail>toto</strEmail> <strTelephone>toto</strTelephone> <strCommentaires>toto</strCommentaires> <blnTopNoMail>toto</blnTopNoMail> </contact>
Maintenant si je veux avoir quelques chose de ce type là :
Y a t il un moyen simple d'arriver à ce résultat ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16<contact> <Utilisateur> <intCivilite>0</intCivilite> <strPrenom>toto</strPrenom> <strNom>toto</strNom> <Utilisateur> <TypeContact> <strMethodeDeContact>toto</strMethodeDeContact> <strEmail>toto</strEmail> <strTelephone>toto</strTelephone> </TypeContact> <strCommentaires>toto</strCommentaires> <blnTopNoMail>toto</blnTopNoMail> </contact>
Pour l'instant le seul moyen que j'ai trouvé c'est d'utiliser des nouveau objets(objet utilisateur & typeContact) rassurez moi y a mieux et plus simple ?
Merci d'avance
PS : Je travaille sur .NET 2.0 et le résultat est envoyé par mail en pièce jointe
PS2 : J'utilise comme méthode de serailization, XmlSerializer
Partager