I have the following XML structure:
<BaseResponse>
<StatusCode>0</StatusCode>
<Text>success</Text>
<DataObject>1111-1111-2222-121212-12121</DataObject>
</BaseResponse>
I am using XmlSerializer
in C# to serialize the XML into a C# object:
public class BaseResponse
{
public int StatusCode { get; set; }
public string Text { get; set; }
public string DataObject { get; set; }
public static BaseResponse Get(string xmlResponse)
{
XmlSerializer serializer = new XmlSerializer(typeof(BaseResponse));
using (StringReader reader = new StringReader(xmlResponse))
{
var responseObj = (BaseResponse)(serializer.Deserialize(reader));
return responseObj;
}
}
}
This works without any problems. But in certain cases the node DataObject
includes children as well. For Example like this (can be any children really):
<BaseResponse>
<Status>0</Status>
<Text>success</Text>
<DataObject>
<DetailStatus>
<Author>Peter</Author>
<DateCreated>21.08.2021 19:00:05</DateCreated>
</DetailStatus>
</DataObject>
</BaseResponse>
Now, with my existing serializing mechanism this XML cant be parsed. Is there any way to tell the XmlSerializer
to parse the children of the node DataObject
as string if there are any. So that BaseResponse.DataObject
would return the children nodes as string.
Like so:
"<DetailStatus><Author>Peter</Author><DateCreated>21.08.2021 19:00:05</DateCreated></DetailStatus>"
Thanks in advance!