You will not be able to deal with this XML using Serialization because you have two different definitions for the B node.
The closest you'll be able to get is:
<A>
<B>
<C>C1</C>
<D>D1</D>
</B>
<B>
<C>C2</C>
<D>D2</D>
</B>
</A>
But first you'll need to sort out the C# classes. Firstly, you have two classes with the same name and an incorrect reference to "B".
Class A should look like this:
[XmlRoot(ElementName = "A")]
public class ParameterA
{
[XmlElement("B")]
public ParameterB B { get; set; }
}
...and class "B" should look like this:
[XmlRoot(ElementName = "B")]
public class ParameterB
{
[XmlElement("C")]
public string Label { get; set; }
[XmlElement("D")]
public string Type { get; set; }
}
That will allow you to get XML that look like:
<A>
<B>
<C>C1</C>
<D>D1</D>
</B>
</A>
Now for the repetition of "B". Modify ParamaterA to have a list of Bs:
[XmlRoot(ElementName = "A")]
public class ParameterA
{
[XmlElement("B")]
public List<ParameterB> B { get; set; }
}
This will allow you to create the XML above.
When you deserialize the XML to the classes you will be able to access the elements of B like this:
var firstParameter = a.B[0];
var secondParameter = a.B[1];
List<T>
allows you to access elements by index (just like an array).
You could also iterate over the values with foreach
:
foreach(ParameterB b in a.B)
{
...
}