I have problems in serializing a list.
Here is my class:
public partial class ProblemType
{
private List<DateTimeType> dateTimeField;
public ProblemType()
{
this.dateTimeField = new List<DateTimeType>();
}
public List<DateTimeType> DateTime
{
get
{
return this.dateTimeField;
}
set
{
this.dateTimeField = value;
}
}
}
public partial class DateTimeType
{
private CodedDescriptionType2 typeField;
private string exactDateTimeField;
public DateTimeType()
{
this.typeField = new CodedDescriptionType2();
}
public CodedDescriptionType2 Type
{
get
{
return this.typeField;
}
set
{
this.typeField = value;
}
}
public string ExactDateTime
{
get
{
return this.exactDateTimeField;
}
set
{
this.exactDateTimeField = value;
}
}
}
My calling code is like this:
ProblemType pt = new ProblemType();
pt.DateTime = GetDateTimeRange();
public List<DateTimeType> GetDateTimeRange()
{
List< DateTimeType> dttList = new List< DateTimeType>();
DateTimeType dtt1 = new CCRG.DateTimeType();
DateTimeType dtt2 = new CCRG.DateTimeType();
dtt1.Type = GetType1();
dtt1.ExactDateTime = GetExactdateTime1();
dttList.Add(dtt1);
dtt2.Type = GetType2();
dtt2.ExactDateTime = GetExactdateTime2();
dttList.Add(dtt2);
return dttList;
}
When I seralize I get XMl like this:
<ProblemType>
<DateTime>
<DateTimeType>
<Type><Text>Episode Begin Datetime</Text></Type>
<ExactDateTime>04/01/2010</ExactDateTime>
</DateTimeType>
<DateTimeType>
<Type><Text>Episode End Datetime</Text></Type>
<ExactDateTime>04/02/2010</ExactDateTime>
</DateTimeType>
</DateTime>
</ProblemType>
I have one problem, I need to get rid of the tag <DateTimeType> becasue the receiving program does not validate it. My output should look like this:
<ProblemType>
<DateTime>
<Type><Text>Episode Begin Datetime</Text></Type>
<ExactDateTime>04/01/2010</ExactDateTime>
</DateTime>
<DateTime>
<Type><Text>Episode End Datetime</Text></Type>
<ExactDateTime>04/02/2010</ExactDateTime>
</DateTime>
</ProblemType>
I have tried several methods and failed. Can somene please help me fix this problem?