I have the below classes:
public class MainRequest
{
private Request _dataField;
[XmlElementAttribute("Parameters")]
public Request Parameters
{
get
{
return _dataField;
}
set
{
_dataField = value;
}
}
}
public class Request
{
private RequestSize _requestSize;
private Field[][] _field;
[XmlElementAttribute(IsNullable = true)]
public RequestSize RequestSize
{
get
{
return _requestSize;
}
set
{
_requestSize = value;
}
}
[XmlArrayItem("BatchEntry")]
[XmlArrayItemAttribute("ParameterEntry", IsNullable = false, NestingLevel = 1)]
public Field[][] Batch
{
get
{
return _field;
}
set
{
_field = value;
}
}
}
public class RequestSize
{
private string _count;
private string _value;
[XmlAttributeAttribute]
public string Count
{
get
{
return _count;
}
set
{
_count = value;
}
}
[XmlTextAttribute]
public string Value
{
get
{
return _value;
}
set
{
_value = value;
}
}
}
public class Field
{
private string _fieldName;
private string _fieldValue;
[XmlAttributeAttribute(AttributeName = "name")]
public string Name
{
get
{
return _fieldName;
}
set
{
_fieldName = value;
}
}
[XmlTextAttribute]
public string Value
{
get
{
return _fieldValue;
}
set
{
_fieldValue = value;
}
}
}
When they are serialized I get:
<Parameters>
<RequestSize Count="1">2</RequestSize>
<Batch>
<BatchEntry>
<ParameterEntry name="AAA">111</ParameterEntry>
<ParameterEntry name="BBB">222</ParameterEntry>
<ParameterEntry name="CCC">333</ParameterEntry>
</BatchEntry>
</Batch>
</Parameters>
I am trying to get rid of the Batch element. What I want the xml to look like is:
<Parameters>
<RequestSize Count="1">2</RequestSize>
<BatchEntry>
<ParameterEntry name="AAA">111</ParameterEntry>
<ParameterEntry name="BBB">222</ParameterEntry>
<ParameterEntry name="CCC">333</ParameterEntry>
</BatchEntry>
</Parameters>
I tried using the XmlElement attribute on the Field[][] but I get an error when I do that:
[XmlElement("Batch")]
public Field[][] Batch
{
get
{
return _field;
}
set
{
_field = value;
}
}
Error 97 Cannot convert type 'Field[][]' to 'Field[]'
Is there a way I can serialize the array elements without that top level element name?