I created a XML model for the purpose of converting SQL resultset to XML file. My model class includes inner classes.
Here is the sample model class for xml.
public class mymodel
{
private const string dec= "declaration",
abc="declaration";
[XmlElement("Item1", Namespace = dec)]
public string Item1{ get; set; }
[XmlRoot("InnerClass", Namespace = dec)]
public class InnerClass
{
[XmlElement("InnerItem", Namespace = abc)]
public string InnerItem{ get; set; }
}
}
Here is my prepared code to convert
DataSet Ds =Get_DataSet_from_Query("Select * from something");
mymodel DpAdv = null;
mymodel InnerClass=null;
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
{
DpAdv = new mymodel
{
Item1= Ds.Tables[0].Rows[i]["ID"].ToString(),
};
InnerClass= new mymodel.InnerClass
{
InnerItem= Ds.Tables[0].Rows[i]["ID"].ToString(),
};
}
And I Called ConvertXML function and passed parameter 'DpAdv' Object
ConvertXML(DpAdv);
Inner Class item Data are not included and missing.
Here is my xml output file . There is missing inner class data.
<?xml version="1.0" encoding="utf-8"?>
<DespatchAdvice xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dec="declaration" >
<dec:Item1>14126</cbc:ID>
</DespatchAdvice>
How can I add all data including inner class data to XML file.