I have a tricky question regarding shallow serialization of List of objects
my entities
public class Requests
{
public string Action { get; set; }
public Meta MetaType { get; set; }
}
public class Meta
{
public string MerchantId { get; set; }
public string IpAddress { get; set; }
public string Version { get; set; }
}
Shallow serialization using XMLSerializer
List<Requests> lstXML = new List<Requests>();
Requests xml = new Requests();
xml.Action = "INSERT";
xml.MetaType = new Meta { IpAddress = "192.2.3.4", MerchantId = "DALE", Version = "1" };
lstXML.Add(xml);
xml = new Requests();
xml.Action = "UPDATE";
xml.MetaType = new Meta { IpAddress = "192.2.3.40", MerchantId = "SECD", Version = "1" };
lstXML.Add(xml);
using (var sw = new StreamWriter(@"C:\XML\test.txt"))
{
var serializer = new XmlSerializer(typeof(List<Requests>));
serializer.Serialize(sw, lstXML);
}
output textfile text.txt
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfRequests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Requests>
<Action>INSERT</Action>
<MetaType>
<MerchantId>DALE</MerchantId>
<IpAddress>192.2.3.4</IpAddress>
<Version>1</Version>
</MetaType>
</Requests>
<Requests>
<Action>UPDATE</Action>
<MetaType>
<MerchantId>SECD</MerchantId>
<IpAddress>192.2.3.40</IpAddress>
<Version>1</Version>
</MetaType>
</Requests>
</ArrayOfRequests>
now my problem is
1) I need to remove the < ?XML version="1.0" ....> and the < ArrayOfRequests ...> tag and retain only the XML tag of my Entities. How can I do that?
2) How can I CAPITALIZE(CAPS) the Element Name ( -> ) in the output textfile?
my desired textfile output would be
<XML>
<REQUESTS>
<ACTION>INSERT</ACTION>
<META>
<MERCHANTID>DALE</MERCHANTID>
<IPADDRESS>202.164.178.163</IPADDRESS>
<VERSION>1</VERSION>
</META>
<REQUESTS>
<REQUESTS>
<ACTION>INSERT</ACTION>
<META>
<MERCHANTID>DALE</MERCHANTID>
<IPADDRESS>202.164.178.163</IPADDRESS>
<VERSION>1</VERSION>
</META>
<REQUESTS>
</XML>
Thanks in advance guys! =)