シリアル化は最良の方法ですか? また、クラス名を同じ (トランザクション) に保つことで、XML ドキュメントのノード名トランザクションを変更できます。クラスで宣言されたパラメーターがあります
public class transaction //Main Class
{
public string propertyID;
public patronInfo TrxPatron;//sub class
public transactioninfo TrxDetails ;// sub class
}
public class patronInfo
{
public string patronID;
}
public class transactioninfo
{
public string Key;
}
static void Main(string[] args)
{
transaction tobj = new transaction();
patronInfo pobj = new patronInfo();
transactioninfo tiobj = new transactioninfo();
tobj.propertyID = "123456";// I add the rest of the values too
string value= SerializeElement("po.xml", tobj);// save to a file
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(value);//I get the xmlfile as a string i convert it into XMl
Console.WriteLine(xdoc.ToString());
Console.Read();
}
// this is my serialization method i use file to avoid compilation error
public static string SerializeElement(string filename,object transactiondetails)
{
XmlSerializer ser = new XmlSerializer(typeof(transaction));
StringWriter sww = new StringWriter();
XmlWriter writer1 = XmlWriter.Create(sww);
ser.Serialize(writer1, transactiondetails);
writer1.Close();
return sww.ToString();
}