I’m going to show you how to convert a List<T> object into a properly formatted XML string you can use to POST to a HTTP endpoint.
First, let me show you my C# POCO classes:
1: [Serializable()]
2: public class GameMatch
3: {
4: public GameMatch()
5: {
6: Summoners = new List<Summoner>();
7: }
8:
9: public int GameId { get; set; }
10: public string MethodType { get; set; }
11: public int GameLength { get; set; }
12: public string GameMode { get; set; }
13: public string GameType { get; set; }
14: public int IpEarned { get; set; }
15: public int IpTotal { get; set; }
16:
17: public List<Summoner> Summoners { get; set; }
18: }
19:
20: [Serializable()]
21: public class Summoner
22: {
23: public Summoner()
24: {
25: Items = new List<Item>();
26: }
27:
28: public List<Item> Items { get; set; } //DONE
29:
30: public int ProfileIconId { get; set; } //DONE
31: public string SummonerName { get; set; } //DONE
32: public int Level { get; set; } //DONE
33: public int ChampionLevel { get; set; } //DONE
34: public bool BotPlayer { get; set; } //DONE
35:
36: public int Wins { get; set; } //DONE
37: public int Losses { get; set; } //DONE
38: public int Leaves { get; set; } //DONE
39:
40: public int NeutralCreepsKilled { get; set; } //DONE
41: public int MinionsKilled { get; set; } //DONE
42: public int ChampionsKilled { get; set; } //DONE
43: public int Assists { get; set; } //DONE
44: public int LargestMultiKill { get; set; } //DONE
45:
46: public string SkinName { get; set; } //DONE
47: public int SummonerSpell1Id { get; set; } //DONE
48: public int SummonerSpell2Id { get; set; } //DONE
49:
50: public int DamageDealt { get; set; } //DONE
51: public int PhysicalDamageDealt { get; set; } //DONE
52: public int MagicDamageDealt { get; set; } //DONE
53: public int LargestCriticalStrike { get; set; } //DONE
54: public int HealingDone { get; set; } //DONE
55:
56: public int PhysicalDamageTaken { get; set; } //DONE
57: public int DamageTaken { get; set; } //DONE
58: public int MagicDamageTaken { get; set; } //DONE
59:
60: public int GoldEarned { get; set; } //DONE
61: public int TimeSpentDead { get; set; } //DONE
62:
63:
64:
65: public int InhibitorsDestroyed { get; set; } //DONE
66: public int TurretsDestroyed { get; set; } //DONE
67:
68: public int Deaths { get; set; } //DONE
69: public int LargestKillingSpree { get; set; } //DONE
70: public int Lose { get; set; } // Maybe this means, 1 = lost; 0 = won? Look into it.
71: }
72:
73: [Serializable()]
74: public class Item
75: {
76: public int ItemId { get; set; }
77: }
Simple easy to understand POCO classes with automatic properties.
Next, to serialize them all we need to do is use a XmlTextWriter and XmlSerialWriter
1: List<GameMatch> parsedMatches = LogParser.Parse(path);
2:
3: StringWriter stringWriter = new StringWriter();
4: XmlDocument xmlDoc = new XmlDocument();
5:
6: XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
7:
8: XmlSerializer serializer = new XmlSerializer(typeof(List<GameMatch>));
9:
10: serializer.Serialize(xmlWriter, parsedMatches);
11:
12: string xmlResult = stringWriter.ToString();
13:
14: xmlDoc.LoadXml(xmlResult);
At this point stringWriter.ToString() will return a pure string of the XML representation of your List<T> object.
Hope this helps!