I have an input XML string with repeating <row> tags that I'm trying to deserialize into an object, but all the rows except the last one get ignored. Any help would be appreciated.
As an example, after the deserialization, the object I get is:
object.command[0].userTable =
{OCI.OCITable}
colHeading: {string[3]}
colHeadingField: {string[3]}
row: {string[3]}
rowField: {string[3]}
This is wrong, because there is only one row in this object, but there should be 4 <row> in the input XML string like this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sessionId xmlns="">feajiofefeaij</sessionId>
<command echo="" xsi:type="UserGetListInServiceProviderResponse" xmlns="">
<userTable>
<colHeading>User Id</colHeading>
<colHeading>Group Id</colHeading>
<colHeading>Name</colHeading>
<row>
<col>1</col>
<col>A</col>
<col>Smith</col>
</row>
<row>
<col>2</col>
<col>A</col>
<col>John</col>
</row>
<row>
<col>3</col>
<col>B</col>
<col>James</col>
</row>
<row>
<col>4</col>
<col>B</col>
<col>Lisa</col>
</row>
</userTable>
</command>
</BroadsoftDocument>
The way I'm doing deserialization is:
MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(responseString));
XmlSerializer ser = new XmlSerializer(typeof(OCIMessage));
OCIMessage response = (OCIMessage)ser.Deserialize(memStream);
And the C# class automatically generated by xsd.exe for the OCITable class is this:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "C")]
public partial class OCITable
{
private string[] colHeadingField;
private string[] rowField;
[System.Xml.Serialization.XmlElementAttribute("colHeading", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] colHeading
{
get
{
return this.colHeadingField;
}
set
{
this.colHeadingField = value;
}
}
[System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("col", typeof(string), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
public string[] row
{
get
{
return this.rowField;
}
set
{
this.rowField = value;
}
}
}