I have a class with the class attribute :
[XmlRoot(ElementName = "RootXML")]
public class Apply
{
/My Properties
}
now to create an xml from the above class I use below function :
public virtual string RenderXml()
{
XmlTextWriter writer = null;
try
{
MemoryStream ms = new MemoryStream();
writer = new XmlTextWriter(ms, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
_xmlSerializer.Serialize(writer, this, ns);
ms.Position = 0;
using (StreamReader sr = new StreamReader(ms))
{
return sr.ReadToEnd();
}
}
finally
{
if (writer != null)
writer.Close();
}
}
My question is how do i add attributes to "RootXML" and read the value of attribute from config file and from function e.g.
<RootXML attr1="read from config" attr2="read from function" >
<Property1>value</Property1>
</RootXML>