I need to set an attribute in my XML. I require the following:
<finAccount version="1.00">
Here is my model so far
[XmlAttribute("version")]
[XmlType("finPOWERConnect")]
public class ApplicationData
{
public List<Account> Accounts;
}
[XmlType("finAccount")]
public class Account
{
//Account stuff
}
The following function serialises my object to xml using the above model.
public Boolean SerialiseObjectToXmlString(Object obj, ref string xml)
{
System.IO.MemoryStream ms = null;
bool Ok = true;
XmlSerializer xmlSerializer = null;
xml = "";
//Serialise
try
{
xmlSerializer = new XmlSerializer(obj.GetType());
ms = new MemoryStream();
xmlSerializer.Serialize(ms, obj);
xml = System.Text.Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
ms.Close();
}
catch(Exception ex)
{
Ok = false;
xml = ex.Message;
}
finally
{
if (ms != null) ms.Dispose();
}
return Ok;
}
I have looked at several examples that set the attribute in the above method however I use this method all throughout the application. Is there a way to set the xml attribute (version="1.00) in the model?